c# - Web service to return different column from different join tables as fields (output) -
i trying create simple webservice takes input parameter , according parameter returns result (from query couple of tables joins) fields different tables, how capture output use in rules while binding 1 infopath form field ???? asap please...
my code below... here getting them string want them different fields...
public class data { //create new method data ** database public static list<string> getdata(string ordnum_10) //public struct getdata(string ordnum_10) { string pmdes1_01 = ""; string descrptn_104 = ""; string prtnum_10 = ""; string ordref_10 = ""; string tnxdte_01 = ""; //create connection sqlconnection con = new sqlconnection(@"data source=*****;initial catalog=eee;integrated security=true;"); //sql command sqlcommand cmd = new sqlcommand("select distinct account_types.descrptn_104, part_master.pmdes1_01,order_master.prtnum_10,order_master.ordnum_10,order_master.ordref_10,part_master.tnxdte_01 from.............. (eum_10 = '"+ ordnum_10 + "'", con); //open connection con.open(); //to read sql server sqldatareader dr = cmd.executereader(); while (dr.read()) { pmdes1_01 = dr["pmdes1_01"].tostring(); prtnum_10 = dr["prtnum_10"].tostring(); descrptn_104 = dr["descrptn_104"].tostring(); ordref_10 = dr["ordref_10"].tostring(); tnxdte_01 = dr["tnxdte_01"].tostring(); } //close connections dr.close(); con.close(); return new list<string> { pmdes1_01, prtnum_10, descrptn_104, ordef_10 }; } }
how string fields can use them in binding in infopath form field ???
in visual studio, click file
menu, new
, select project
. find asp.net empty web application
within web
. give sensible name , click ok
. in solution explorer, right-click new project under solution, click add
, select new item
, find web service
within web
. name data.asmx
, click add
. should see code behind new web service data
class.
now can declare own class represent database record, e.g. see class record
below. create instances of record
in getdata()
method calling get*type*() methods on sqldatareader
. you'll need @ data types on database columns , call appropriate method e.g. getstring()
, getint32()
etc...
class data : system.web.services.webservice { public class record { public string accounttype { get; set; } public string partdescription { get; set; } public int partnumber { get; set; } public string orderref { get; set; } public datetime transactiondate { get; set; } } [webmethod] public static list<record> getdata(string param) { sqlconnection con = new sqlconnection(@"connectionstring"); con.open(); sqlcommand cmd = new sqlcommand("select type,desc,num,ref,date foo", con); sqldatareader dr = cmd.executereader(); list<record> records = new list<record>(); while (dr.read()) { records.add(new record() { accounttype = dr.getstring(0), partdescription = dr.getstring(1), partnumber = dr.getint32(2), orderref = dr.getstring(3), transactiondate = dr.getdatetime(4) }); } dr.close(); con.close(); return records; } }
hint: it's better add parameters query via cmd.parameters
collection rather using string concatenation.
now should in position run or deploy web service , url of wsdl. example of calling infopath, there nice walk-through here.
Comments
Post a Comment