- static public string table2Json(DataSet ds, int table_no)
- {
- try
- {
- // Given a Dataset & Table NO , function returns a 2 dim JSON Array of values in that table
- int rcnt = ds.Tables[table_no].Rows.Count; // Row Count
- int ccnt = ds.Tables[table_no].Columns.Count; // Col Count
- object[][] tb = new object[rcnt][];
- int r = 0;
- foreach (DataRow dr in ds.Tables[table_no].Rows)
- {
- tb[r] = new object[ccnt];
- for (int col = 0; col < ccnt; col++)
- {
- tb[r][col] = dr[col];
- if ((tb[r][col]).Equals(System.DBNull.Value))
- tb[r][col] = "";
- }
- r++;
- }
- var table= JsonConvert.SerializeObject(tb);
- return table;
- }
Loading

Amit MohantyRank #112 · 20K reputationPosted Oct 17, 2019, 9:14 PM EDT
Sanjay gautam88 reputationPosted Oct 17, 2019, 9:19 PM EDT
Amit MohantyRank #112 · 20K reputationPosted Oct 17, 2019, 9:23 PM EDT
Mageshwaran RRank #411 · 6.1K reputationPosted Nov 25, 2019, 4:56 AM EST