User-1909855381 posted
Hello Microsft team,
the issue is after bind list data to datatable and when I pass to Table value parameter of a store procedure that SP is not executed. when tracing in the profiler.
public async System.Threading.Tasks.Task<string> ViewLeadSyncAPIConfigs()
{
try
{
List<LeadItems> lstItems = new List<LeadItems>();
var Baseurl = "https://www.APIURL.com/";
using (var client = new HttpClient())
{
client.BaseAddress = new Uri(Baseurl);
client.DefaultRequestHeaders.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage Res = await client.GetAsync("url").ConfigureAwait(false);
if (Res.IsSuccessStatusCode)
{
var result = Res.Content.ReadAsStringAsync().Result;
lstItems = JsonConvert.DeserializeObject<List<LeadItems>>(result);
}
}
var tableData = ConvertToDataTable<LeadItems>(lstItems);
var dataResult = AddFromTradeIndia(tableData);
return dataResult;
}
catch (Exception)
{
throw;
}
}
public DataTable ConvertToDataTable<T>(List<T> items)
{
DataTable dataTable = new DataTable(typeof(T).Name);
//Get all the properties
System.Reflection.PropertyInfo[] Props = typeof(T).GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);
foreach (System.Reflection.PropertyInfo prop in Props)
{
//Defining type of data column gives proper data table
var type = (prop.PropertyType.IsGenericType && prop.PropertyType.GetGenericTypeDefinition() == typeof(Nullable<>) ? Nullable.GetUnderlyingType(prop.PropertyType) : prop.PropertyType);
//Setting column names as Property names
dataTable.Columns.Add(prop.Name, type);
}
foreach (T item in items)
{
var values = new object[Props.Length];
for (int i = 0; i < Props.Length; i++)
{
//inserting property values to datatable rows
values[i] = Props[i].GetValue(item, null);
}
dataTable.Rows.Add(values);
}
//put a breakpoint here and check datatable
return dataTable;
}
public string AddLeadFromTradeIndia(DataTable items)
{
try
{
object[] obj = new object[]
{"@ManageLeadType",items
};
return _SqlHelper.ExecuteQuery(con, "InsertTradeIndiaData", obj);
}
catch (Exception)
{
throw;
}
}
Thank you ,