Infopath 2010 form binding data to dropdownlist from web service

A short code snippet to get the data from the web service and binding to dropdownlist.

First of all create a web service that returns a data set ,create a dataconnection from infopath that retrieves data from web service and binding data source to drop down list.

 

1) Creating web service

[WebMethod]
public DataSet RegCust()
{
string returnstr = “Insert failed”;
SqlConnection dbConn = new SqlConnection(“database=ims;server=192.168.0.111;uid=sa;password=@System”);
string sqlstr = “select productid,productname,unitprice,numofitems,TotalAmount from tblorderdetails”;
SqlCommand dbComm = new SqlCommand(sqlstr, dbConn);
try
{
dbConn.Open();
SqlDataAdapter da = new SqlDataAdapter(dbComm);
ds = new DataSet();
da.Fill(ds);
if (ds.Tables[0].Rows.Count != 0)
{
returnstr = “Insert succeeded”;
}
returnstr = “Insert succeeded”;
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
dbConn.Close();
return ds;
}

Debug this and copy the URL:http://localhost:1983/getCompanyName.asmx

Image

2)Create dataconnection to retrive data from web service using infopath 

Steps:1) Click on “Data-Data Connections” from top ribbon

Image

2)Add a new connection from the DataConnections wizard

Image

3) Select operation Retrive 

Image

4)Select a source type,since it is a web service..we select first option

Image

5)Get the web servie details using the URL Copied from the above stepImage

7)Select the method that returns datasetImage

8)Clcik next and next

 

Binding Data Source to DropDownList

1)Right click on the drop down list and select “drop down list properties” and select “Get choices from the external data sources”

Image

 

2)Select the field that you want to display in the drop down list as follows

Image

3)Preview to see the output

Advertisements

About alekhyakodamsharepoint

Hi.. I am alekhya working as a sharepoint developer.
This entry was posted in Infopath 2010. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s