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"
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.
oledbadapter.fill(dataset)
combobox.datasource=dataset.tables(0).defualtview
combobox.datamember="EmployeeType"
combobox.Valuemember="EmployeeID"
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.
it's useful
ReplyDelete