我在C#和.NET方面还很新手,不过我写了这段代码来调用一个存储过程,并想将返回的DataTable转换为JSON格式。
SqlConnection con = new SqlConnection("connection string here");
SqlDataAdapter da = new SqlDataAdapter();
SqlCommand cmd = new SqlCommand("getDates", con);
SqlParameter par = new SqlParameter("@PlaceID", SqlDbType.Int);
par.Value = 42;
da.SelectCommand = cmd;
cmd.Parameters.Add(par);
DataSet ds = new DataSet();
DataTable dt = new DataTable();
con.Open();
try{
cmd.CommandType = CommandType.StoredProcedure;
da.Fill(ds);
}
那么我的问题是如何以最佳/最简单的方式做到这一点?如果能提供示例就更好了,因为我还很陌生。