How to display the actual result of sql server data in the HTML page using Web Service? -
i'm using below store procedure.
declare @body varchar(max) set @body = cast( ( select td = cast( ivoucher_type_id varchar(30)) + '</td><td>' + cast( cvoucher_type varchar(30)) + '</td><td>' + cast( dvoucher_date varchar(30)) ( select ivoucher_type_id, cvoucher_type, dvoucher_date master.dbo.mast_voucher_type ) d xml path( 'tr' ), type ) varchar(max) ) set @body = '<tr><th>voucher type id</th><th>voucher type</th><th>voucher date</th></tr>' + replace( replace( @body, '<', '<' ), '>', '>' ) print @body
in return result below format
<tr> <th>voucher type id</th> <th>voucher type</th> <th>voucher date</th> </tr> <tr> <td>1</td> <td>test 1</td> <td>mar 27 2016 4:08pm</td> </tr>
i'm using below web service code. in how can display same output in web service. in web service output not working shows empty [ ].
[webmethod()] public string getdataset(string strquery, string strcon) { datatable dt = new datatable(); using (system.data.sqlclient.sqlconnection conn = new system.data.sqlclient.sqlconnection()) { conn.connectionstring = system.configuration.configurationmanager.appsettings["bb_constr"]; using (system.data.sqlclient.sqlcommand cmd = new system.data.sqlclient.sqlcommand()) { cmd.commandtext = strquery; cmd.connection = conn; conn.open(); sqldataadapter da = new sqldataadapter(cmd); da.fill(dt); system.web.script.serialization.javascriptserializer serializer = new system.web.script.serialization.javascriptserializer(); list<dictionary<string, object>> rows = new list<dictionary<string, object>>(); dictionary<string, object> row = default(dictionary<string, object>); foreach (datarow dr in dt.rows) { row = new dictionary<string, object>(); foreach (datacolumn col in dt.columns) { row.add(col.columnname, dr[col]); } rows.add(row); } return serializer.serialize(rows); } } }
need web service display exact output of sql server(without serialize or change code).
replace print select:
declare @body varchar(max) set @body = cast( ( select td = cast( ivoucher_type_id varchar(30)) + '</td><td>' + cast( cvoucher_type varchar(30)) + '</td><td>' + cast( dvoucher_date varchar(30)) ( select ivoucher_type_id, cvoucher_type, dvoucher_date master.dbo.mast_voucher_type ) d xml path( 'tr' ), type ) varchar(max) ) set @body = '<tr><th>voucher type id</th><th>voucher type</th><th>voucher date</th></tr>' + replace( replace( @body, '<', '<' ), '>', '>' ) select @body
return result without serialization
[webmethod()] public string getdataset(string strquery, string strcon) { string connstr = system.configuration.configurationmanager.appsettings["bb_constr"]; using (sqlconnection conn = new sqlconnection(connstr)) { sqlcommand cmd = new sqlcommand() cmd.commandtext = strquery; cmd.connection = conn; conn.open(); object result = cmd.executescalar(); if (result == dbnull.value) throw new applicationexception("oh no"); return result.tostring(); } }
Comments
Post a Comment