如何将具有多个数据的数据集转换为json [英] how to convert dataset with multiple datable to json
本文介绍了如何将具有多个数据的数据集转换为json的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含多个数据表的数据集,我想将每个数据表绑定到安培图表,
为此我需要将每个数据表转换为json对象然后绑定我的图表。
单个数据表我的代码如下
Hi,
I have a dataset with has multiple datatable ,I want to bind each datatable to ampie charts ,
for this i need to convert each datatable to json object and then bind my charts.
for single datatable my code is as follow
[WebMethod]
public static UserDetails[] BindDatatable(long pvid, long deptid, long locid, long blgid, string article)
{
DataTable dt = new DataTable();
List<UserDetails> details = new List<UserDetails>();
//string connectionstring = "Data Source=DCS_SERVER;Initial Catalog=DSIM_CLOUD;User ID=sa;Password=sa123;Timeout=200";
string connectionstring = ConfigurationManager.ConnectionStrings[System.Web.HttpContext.Current.Session["ConnectionStringNuggettsCloud"].ToString()].ConnectionString;
SqlConnection con = new SqlConnection(connectionstring);
con.Open();
SqlCommand comm = new SqlCommand("usp_ReportException", con);
comm.CommandType = CommandType.StoredProcedure;
comm.Parameters.Add("@pvid", SqlDbType.BigInt).Value = pvid;
SqlDataAdapter da = new SqlDataAdapter(comm);
da.Fill(dt);
foreach (DataRow dtrow in dt.Rows)
{
UserDetails user = new UserDetails();
user.Article_desc = dtrow["Article_desc"].ToString();
user.model = dtrow["model"].ToString();
details.Add(user);
}
con.Close();
// }
return details.ToArray();
}
public class UserDetails
{
public string Article_desc { get; set; }
public string model { get; set; }
}
<script type="text/javascript">
$(document).ready(function () {
// debugger
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "ExceptionReport.aspx/BindDatatable",
data: "{pvid:" + $("#hndPVID")[0].value + ",deptid:" + $("#hndDeptid")[0].value + ",locid:" + $("#hndLocid")[0].value + ",blgid:" + $("#hndBlgid")[0].value + ",article:" + $("#hndArticle")[0].value + "}",
dataType: "json",
success: function (data) {
// debugger
},
error: function (result) {
alert("Error");
}
});
});
</script>
这是我用单个数据表绑定图表的方式,如果有多个数据集的话数据表然后怎么可能请帮忙。
This is way i am binding charts with single datatable ,with if there is dataset with multiple datatable then how is it possible please help.
SqlDataAdapter da = new SqlDataAdapter(comm);
da.Fill(ds);
然后我将如何将具有多个数据表的数据集转换为json?
then how will i convert dataset with multiple datatable to json ??
推荐答案
(document).ready(function(){
// debugger
(document).ready(function () { // debugger
.ajax({
type:POST,
contentType:application / json; charset = utf-8,
url:ExceptionReport.aspx / BindDatatable,
data:{pvid:+
.ajax({ type: "POST", contentType: "application/json; charset=utf-8", url: "ExceptionReport.aspx/BindDatatable", data: "{pvid:" +
(#hndPVID)[0] .value +,deptid:+
("#hndPVID")[0].value + ",deptid:" +
这篇关于如何将具有多个数据的数据集转换为json的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文