how to store this response from external API to an existing table using stored procedure. I need to store the joined date , employee id
from api response:
"Employee joined Date","Employee ID","Job ID","Status"
"2023-06-09T09:32:49",123456","REF11","Open"
"2023-07-09T09:32:49",1234516","REF101","closed"
"2023-08-09T09:32:49",1234567","REF121","Open"
Jayraj ChhayaPosted Jan 15, 2024, 6:19 AM
To store the API response in an existing table using a stored procedure, you can follow these steps:
Create a stored procedure in your database that accepts the necessary parameters to store the data. In this case, the parameters would be the "Employee Joined Date" and "Employee ID".
Parse the API response and extract the required data. You can use a JSON parser or any other suitable method to extract the values of "Employee Joined Date" and "Employee ID" from the API response.
Call the stored procedure from your code and pass the extracted values as parameters. Here's an example of how you can do this in C# using ADO.NET:
Make sure to replace "YourStoredProcedureName" with the actual name of your stored procedure, and provide the correct connection string.
By following these steps, you will be able to store the "Employee Joined Date" and "Employee ID" from the API response into an existing table using a stored procedure.
Prasad RaveendranPosted Jan 13, 2024, 5:37 PM
Hello Meghana,
There are various ways to save the response in the database, but a clear understanding of your requirements is essential. Once we have clarity on your needs, we can propose a more tailored solution.
Sachin SinghPosted Jan 12, 2024, 2:23 PM
You can do it like this in c# app
your api method
Uttam ChaturvediPosted Jan 12, 2024, 1:33 PM
I would have written some generic method to read JSON in to c# table and store in datatbase. Below is example to read Json in table. Below are the steps:
>(jsonString);
public static DataTable ToDataTable(this IList data)
{
PropertyDescriptorCollection props =
TypeDescriptor.GetProperties(typeof(T));
DataTable table = new DataTable();
for(int i = 0 ; i < props.Count ; i++)
{
PropertyDescriptor prop = props[i];
table.Columns.Add(prop.Name, prop.PropertyType);
}
object[] values = new object[props.Count];
foreach (T item in data)
{
for (int i = 0; i < values.Length; i++)
{
values[i] = props[i].GetValue(item);
}
table.Rows.Add(values);
}
return table;
}
Please accept answer, if you find it useful
Alpesh ManiyaPosted Jan 12, 2024, 1:11 PM
You may use OPENJSON function to retrive the json data and store it in SQL table. Below is the sample code snipet to achieve it.