dynamic data access using combobox

renjivraman

Member
Joined
Sep 9, 2006
Messages
23
Location
India
Programming Experience
1-3
hai all im doin a project in vb.net 2003 with sql support in which i have to use dynamic binding with combobox my code is as follows:
VB.NET:
ds = oservices.getdataset("select DEALERNAME from adealer")
Me.dealercombo.DataSource = ds.Tables(0)
Me.dealercombo.DisplayMember = "adealer.DEALERNAME"
here OSERVICES is a dataservice class defined by me ,the function GETDATASET will return a dataset which contain the values for the select statementin the first line.. to DS which is of type dataset, but when i run this thing im just getting something like SYSTEM.DATAVIEW.DATAROW with in the combobox dropdownlist...so pls help me solving this..regards renjiv
 
Last edited by a moderator:
Your DisplayMember is invalid. You've bound a DataTable to the DataSource property and that DataTable has no column named "adealer.DEALERNAME". If you bind the DataSet to the DataSource, then you need to qualify the column name with the table name:
VB.NET:
Me.dealercombo.DataSource = [U][B]ds[/B][/U]
Me.dealercombo.DisplayMember = [U][B]"adealer.DEALERNAME"[/B][/U]
If you bind the DataTable you don't:
VB.NET:
Me.dealercombo.DataSource = [U][B]ds.Tables(0)[/B][/U]
Me.dealercombo.DisplayMember = [U][B]"DEALERNAME"[/B][/U]
 
if adealer is the name of the table, youre always better using table names rather than numbers.:

Me.dealercombo.DataSource = ds.Tables("adealer")
Me.dealercombo.DisplayMember = "DEALERNAME"

If the concept of "magic numbers" in code is typical to you you should consider changing your coding strategies; try less often to use magic numbers. Give things names so you can be sure of what youre looking at. What if Tables(0) isnt the adealer table at all?​
 
Back
Top