1. Get DataSet
2. Convert to DataTable
3.
public static string DataTableToJson(DataTable dt)
{
StringBuilder jsonBuilder = new StringBuilder();
//("{"); //Do not require '}'
//();
("[");
for (int i = 0; i < ; i++)
{
("{");
for (int j = 0; j < ; j++)
{
("\"");
([j].ColumnName);
("\":\"");
([i][j].ToString());
("\",");
}
( - 1, 1);
("},");
}
( - 1, 1);
("]");
//("}"); //Do not output requirements '}'
return ();
}
4. Response the Json string
5. Get Json string
function load() //page loading
{
$.ajax({
type:"post",
url:"../Handler/",//Where to get Json
data:"action=getLinkMan&#divImage").hide();
if(mess!="]")// If the retrieved data is not empty
{
var type=eval(mess);
var str="<a>Home</a>"
for(var i=0;i<;i++)
{
//Operate type to get stuff
str+="<a>"+type[i].Database field name+"</a>
}
$("#divLinkMan").html(str);//Embed str into div divLinkMan
}
else
{
var notfind="<h2>No data found<a href='../' target='_parent'>Returned</a></h2>"
$("#divLinkMan").html(notfind);
}
},
complete:function()
{
//All methods after execution
}
});
}