public static string Createjsonparameters (DataTable dt)
{
/* /****************************************************************************
* Without goingin to the depth of the functioning of this Method, I'll try to give an overview
* As soon as this method gets a DataTable it starts to convert it into JSON String,
* It takes each row and with each row it grabs the cell name and its data.
* This kind of JSON was very usefull when developer has to have the Column name of the.
* Values Can is Access on the clien in the this. Obj. Head[0].<columnname>
* Note:one negative point. By this method, user'll is not being able to call any cell by its index.
* *************************************************************************/
StringBuilder jsonstring = new StringBuilder ();
Exception Handling
if (dt! = null && dt. Rows.Count > 0)
{
Jsonstring.append ("{");
Jsonstring.append ("\" head\ ": [");
for (int i = 0; i < dt. Rows.Count; i++)
{
Jsonstring.append ("{");
for (int j = 0; j < dt. Columns.count; J + +)
{
if (J < dt. COLUMNS.COUNT-1)
{
Jsonstring.append ("\" "+ dt. COLUMNS[J]. Columnname.tostring () + "\": "+" \ "" + dt. ROWS[I][J]. ToString () + "\", ");
}
else if (j = = dt. COLUMNS.COUNT-1)
{
Jsonstring.append ("\" "+ dt. COLUMNS[J]. Columnname.tostring () + "\": "+" \ "" + dt. ROWS[I][J]. ToString () + "\" ");
}
}
/*end of string*/
if (i = = dt. ROWS.COUNT-1)
{
Jsonstring.append ("}");
}
Else
{
Jsonstring.append ("},");
}
}
Jsonstring.append ("]}");
return jsonstring.tostring ();
}
Else
{
return null;
}
}
JSON and the DataTable (DataSet) transform each other