I have a stored procedure that returns the results of a query as json, and I want to understand how this query gets into my code in an ASP.NET application.
Stored Procedure:
Select
SUBJECT AS [subject],
STARTDATE AS [start]
ENDDATE AS [end],
ID AS [id]
FROM
SOME_TABLE
FOR JSON PATH
Json format from stored procedure:
[
{
"subject": _,
"start": _,
"end":_,
"id":_
},
...]
aspx.cs codebehind
(fragment from function)
try
{
if (sqlcon.State == ConnectionState.Closed)
{
sqlcon.Open();
}
SqlCommand sccmd = new SqlCommand("MY_STORED_PROCEDURE", sqlcon);
sccmd.CommandType = CommandType.StoredProcedure;
sccmd.Parameters.AddWithValue("@value1", valueID);
sccmd.Parameters.AddWithValue("@value2", valueID);
SqlDataReader sdrreader = sccmd.ExecuteReader();
while (sdrreader.Read())
{
// lost on what to do here
}
sdrreader.Close();
}
catch (Exception ex){}
finally { sqlcon.Close(); }
I want to keep this json response in my code, but I don't know how to do it. Before making a json answer, I used SqlDataReaderc Read()to go through each entry, but how will this work if now the answer is json; is there another class that will specifically handle the json response?
Clarification please!
source
share