When I run a query on sql server from C # the fields of the date type are extracted as Date(1445580000000)
when formatted in JSON. Although in the query specify the CONVERT to do so in yyyy-mm-dd
, the same thing happened to me once in php and the connection specified something like GetDateAsString=>true
for solve it.
It is possible to define that in the connection or in the sqlCommand or DataReader , or I have to go through the data to convert the date manually, and then go back through it to turn it into JSON . What will consume me more resources, since they are more than 10 thousand rows . Any ideas?
DataTable dt = new DataTable();
SqlConnection sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["CIS"].ConnectionString);
string select = "EXECUTE dbo.getInforme";
sqlConnection.Open();
SqlDataAdapter da = new SqlDataAdapter(select, sqlConnection);
da.Fill(dt);
System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
List<Dictionary<string, object>> rows = new List<Dictionary<string, object>>();
Dictionary<string, object> row;
foreach (DataRow dr in dt.Rows)
{
row = new Dictionary<string, object>();
foreach (DataColumn col in dt.Columns)
{
row.Add(col.ColumnName, dr[col]);
}
rows.Add(row);
}
sqlConnection.Close();
serializer.MaxJsonLength = Int32.MaxValue;
Response.Write(serializer.Serialize(rows));
Note: dbo.getReport is a stored procedure that returns this information