Posts

Showing posts from January, 2024

RETURN JSON FROM SQL SERVER as QUERY RESULT

Get as It is Json Body : select ID,MobileNo,FullName,EmailID,DistrictName,TalukaName,VillageName from UserRegistrations  For JSON PATH With Root Json Body :  select ID,MobileNo,FullName,EmailID,DistrictName,TalukaName,VillageName from UserRegistrations  For JSON PATH , ROOT('UserData')  C# Code To Read : public class data { public DateTime date {get;set;} public string name {get;set;} public int numbers {get;set;} } public ActionResult GetAllSummary() { string connectionString ="Data Source=...;Initial Catalog=...;Integrated Security=True"; string query = "SELECT DISTINCT v.date, v.name, v.numbers FROM view as v ORDER BY v.date,v.name,v.numbers"; using(SqlConnection conn = new SqlConnection(connectionString)) { SqlCommand command = new SqlCommand(query, conn); try { conn.Open(); SqlDataReader reader = command.ExecuteReader(); // In this part below, I want the SqlDataReader to ...