I have some code for convert table to json
want to remove all loop with the help of linq
any way to convert foreach to linq
how does i do
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++;
}
//JavaScriptSerializer js = new JavaScriptSerializer();
// return js.Serialize(tb);
var table= JsonConvert.SerializeObject(tb); //change by sanjay 15/10/2019 using newtonsoft json
return table;
}