I wrote it myself, but now I need to back up and save it. there will be problems at that time.
Using system; using system. data; using system. configuration; using system. collections; using system. web; using system. web. security; using system. web. ui; using system. web. UI. webcontrols; using system. web. UI. webcontrols. webparts; using system. web. UI. htmlcontrols; using system. text; using system. data. sqlclient; public partial class station_name_data: system. web. UI. page {protected string strstation_name = string. empty; protected void page_load (Object sender, eventargs e) {string factory_name = request. form ["factoryname"]. trim (); sqlconnection conn_stationname = new sqlconnection (); conn_stationname.connectionstring = system. configuration. configurationmanager. connectionstrings ["xnyw.gs"]. connectionstring; try {conn_stationname.open (); sqlcommand cmd_station = new sqlcommand (); __station.connection = conn_stationname; __station.commandtext = "select station_id, station_name from station_info inner join factory_info on station_info.factory_id = exist where region = '"+ factory_name +"' "; sqldataadapter SDA = new sqldataadapter (pai_station); dataset DS = new dataset (); SDA. fill (DS); // strcompany_name + = "["; // For (INT I = 0; I <Ds. tables [0]. rows. count; I ++) // {// The last line is processed separately. // The format is as follows: // * [{"servicehall_name ": "Name 1", "servicehall_id": "1" },{ "servicehall_name": "name 2", "servicehall_id ": "2"}] // * // string id = Ds. tables [0]. rows [I] [0]. tostring (). trim (); // string company_name = Ds. tables [0]. rows [I] [1]. tostring (). trim (); // strcompany_name + = "'{company_id': '" + ID + "',"; // strcompany_name + = "'Company _ name ': '"+ company_name +"'}, "; // strcompany_name = strcompany_name.remove (strcompany_name.length-1); // strcompany_name + ="] "; datatable dt = Ds. tables [0]; strstation_name = datatabletojson (DT, "rootstationname", 0, DT. rows. count);} catch (exception ex) {console. writeline (ex. message);} finally {conn_stationname.close ();} httpcontext. current. response. write (strstation_name); httpcontext. current. response. end () ;}public static string datatabletojson (datatable DT, string strtablename, int start, int limit) {stringbuilder jsonbuilder = new stringbuilder (); string head = "{success: True, \ "totalrecordcount \": \ "" + dt. rows. count. tostring () + "\", \ "; // jsonbuilder. append ("{\" "); string tmpstr =" "; jsonbuilder. append (strtablename); jsonbuilder. append ("\": ["); If (DT. rows. count> 0) {int endcount = start + limit; If (endcount> DT. rows. count) endcount = DT. rows. count; For (INT I = start; I <endcount; I ++) {jsonbuilder. append ("{"); For (Int J = 0; j <DT. columns. count; j ++) {jsonbuilder. append ("\" "); jsonbuilder. append (DT. columns [J]. columnname); jsonbuilder. append ("\": \ ""); tmpstr = DT. rows [I] [J]. tostring (). trim (); jsonbuilder. append (tmpstr. replace ("\" "," \ ""); jsonbuilder. append ("\", ");} jsonbuilder. remove (jsonbuilder. length-1, 1); jsonbuilder. append ("},");} jsonbuilder. remove (jsonbuilder. length-1, 1);} jsonbuilder. append ("]"); jsonbuilder. append ("}"); return head + jsonbuilder. tostring ();}}