i creating web service in asp.net serialize data in json format, , access webservice via jquery
using system; using system.io; using system.net; using system.web; using system.linq; using system.web.hosting; using system.web.services; using system.web.script.services; using system.collections.generic; using system.web.script.serialization; namespace chart_webservice { /// <summary> /// summary description service /// </summary> [webservice(namespace = "http://tempuri.org/")] [webservicebinding(conformsto = wsiprofiles.basicprofile1_1)] [system.componentmodel.toolboxitem(false)] [scriptservice] // allow web service called script, using asp.net ajax, uncomment following line. // [system.web.script.services.scriptservice] public class service : system.web.services.webservice { [webmethod] [scriptmethod(usehttpget = true, responseformat = responseformat.json)] public datatable getdata() { string constr = configurationmanager.connectionstrings["constr"].connectionstring; using (sqlconnection con = new sqlconnection(constr)) { using (sqlcommand cmd = new sqlcommand("select * customers")) { using (sqldataadapter sda = new sqldataadapter()) { cmd.connection = con; sda.selectcommand = cmd; using (datatable dt = new datatable()) { dt.tablename = "customers"; sda.fill(dt); return dt; } } } } } } }
please me complete solution because not have idea complete hope @ guys!
i not return datatable
. can use raw ado.net , fill result simple dictionary<string, object>
. newtonsoft.json
can serialize dictionary , return it.
Comments
Post a Comment