I'm trying to insert data into a SQL Server database using a console application. Data to be inserted is in a json object (it is the web api post method request body). Can anyone please tell me how to use json object to insert into a SQL Server database?
Here is the code:
namespace CreateEntityConsole
{
class Entity
{
string domain = "DESKTOP-I4VK2LV";
string userName = "AP-502";
string password = "pass";
string appID = "bbb";
string locale = "en-US";
string contenttype = string.Empty;
// Create ENTITY
public string CreateEntity()
{
string URI = "http://localhost:13490/agilepointserver/extension/createentity";
string JsonRequestData = "{\"EntityName\":[\"AccountContact\":[\"PropertiesJSON\":[\"AName\": \"chaitratest2\",\"region\": \"India\"]]]}";
HttpOperations ops = new HttpOperations(domain, this.userName, password, appID, locale);
// HttpOperations ops = new HttpOperations(this.userName, password, appID, locale);
return ops.InsertEntity(URI, JsonRequestData);
}
public void InsertIntoDB(string JsonRequestData)
{
using (SqlConnection sqlCon = new SqlConnection())
{
sqlCon.ConnectionString = "server=DESKTOP-I4VK2LV;Integrated Security=True;database=Entity";
sqlCon.Open();
}
}
}
}