MSSQL,SqlCommand, SqlDataAdapter,DataTable, Dictionary, List,JavaScriptSerializer,
SqlCommand cmd = new SqlCommand(sqlstring, conn); //自行定義sqlstring 及 conn
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
sda.Fill(dt);
conn.Close();
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);
}
JavaScriptSerializer jss = new JavaScriptSerializer();
string value = jss.Serialize(rows).ToString(); //json序列化