我正在尝试将查询结果转换为 json。
string esql = "select d.dpr_ts, d.dpr_close from Entities3.dpr_mm as d";//where dpr_qot_id=2029543939 and dpr_ts>='" + start + "' and dpr_ts<='" + end + "'";
EntityConnection econn = new EntityConnection("name=Entities3");
econn.Open();
EntityCommand ecmd = econn.CreateCommand();
ecmd.CommandText = esql;
EntityDataReader ereader = ecmd.ExecuteReader(CommandBehavior.SequentialAccess);
Console.WriteLine("Entity SQL Result");
StringBuilder result = new StringBuilder();
int i = 0;
while (ereader.Read())
{
if (i > 0) result.Append(","); i++;
result.Append("['" + ereader.GetDateTime(0).ToShortDateString() + "'," + ereader.GetValue(1) + "]");
}
ViewBag.ChartData = "[" + result.ToString() + "]";
我想把它保存在 ViewBag 中。但结果字符串看起来像:(['10.01.2011',3,9990],['11.01.2011']
所以"'"
被转换为'
)。我怎样才能避免它?
顺便说一句:我通常可以更好地完成这项任务吗?