How to convert foreach loop in linq there is any esay way to change loop to linq i have some code showen blewo
- static public string table2Json(DataSet ds, int table_no)
- {
-
- try
- {
- object[][] tb = new object[ds.Tables[table_no].Rows.Count][];
-
- int r = 0;
- foreach (DataRow dr in ds.Tables[table_no].Rows)
- {
- tb[r] = new object[ds.Tables[table_no].Columns.Count];
- int col = 0;
-
- foreach (DataColumn column in ds.Tables[table_no].Columns)
- {
- tb[r][col] = dr[col];
- if ((tb[r][col]).Equals(System.DBNull.Value))
- {
- tb[r][col] = "";
- }
- col++;
- }
- r++;
- }
- string table = JsonConvert.SerializeObject(tb, Formatting.Indented);
- return table;
- }
- catch (Exception ex)
- {
- tools.log(ex.Message);
- throw ex;
- }
- }