Expert Answer Center > Experts On Demand > View Answer
EMAIL THIS
Experts on Demand
  EXPERTS ON DEMAND HOME     POSE A QUESTION     VIEW ANSWERS     BROWSE BY TOPIC        RSS FEEDS  
I am creating a database application, and I want to fill the combo box with a dataset using Datamember and value member, but the following code leaves the combo box empty. I want to know the correct way to populate the combo box using the dataset.
oledbadapter.fill(dataset)
combobox.datasource=dataset.tables(0).defualtview
combobox.datamember="EmployeeType"
 combobox.Valuemember="EmployeeID"
QUESTION POSED ON: 15 SEP 2005
QUESTION ANSWERED BY: Andrew Young Is this application for an ASP.Net Web page or a Windows form? If this is for an APS.NET web application, use one of the available list bound controls. As long as you have properly set your datasource and datamember properties in your dataadapter, all you need to do is call the databind method on your list bound control. I have done it using a listbox(myLst), in this case:
oledbadapter.fill(dataset);
myLst.DataBind();
Put this code into your Page_Load event:
c#
If(!Page.IsPostBack)
{
oledbadapter.fill(dataset);
myLst.DataBind();
}

vb:
If Not Page.IsPostBack Then
oledbadapter.fill(dataset)
myLst.DataBind()
End If
It is all dependant, of course, upon the assumption that you have your dataadapter connected with a valid connection object and defined correctly.
HomeExperts on DemandIT Expert Webcast SeriesExpert KnowledgebaseSite Index
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts