Problem binding combobox to dataset

P

Poonam

I have a department table with DeptID and DeptName. I am trying to fill
my combobox with DeptName.

Here is my code but it does not work? Can someone help me?

Dim pxy As New Channel1.Channel
dsDepts = pxy.getDepartments()
cmbDept.DisplayMember = "DeptName"
cmbDept.ValueMember = "DeptID"
cmbDept.DataSource = dsDepts.Tables("Department")

This does not give any error but it does not fill my combobox. It
remains empty.

if I give the following:
cmbDept.Datasource = dsdepts

it fills the combobox with the following:
System.Data.DataViewManagerListItemTypeDescriptor

Also do I have to add the databindings property or not?

getdepartments webmethod simply returns the dataset.

the following does not work.
cmbDept.DataSource = dsDepts.Tables(0)


It's urgent. I need help.
Poonam
 
K

Kevin Hodgson

Here is the code I use to do something similar. You need to bind both the
DisplayMember and ValueMember to one column, and I use the Tag property to
store my ID Field.

Try something like this.
cmbDept.DataBindings.Add(New System.Windows.Forms.Binding("Tag", dsDepts,
"tablename.DeptID"))cmbDept.DataSource =DsDepts
cmbDept.DisplayMember = "tablename.DeptName"
cmbDept.ValueMember = "tablename.DeptName"
 
B

Brian Swanson

You have to run the cmbDept.Refresh after assigning the DisplayMember,
ValueMember and DataSource.

Hope this helps,
Brian Swanson
 
P

Poonam

cmbDept.DisplayMember = "Department.DeptName"
cmbDept.ValueMember = "Department.DeptName"
cmbDept.DataSource = dsDepts
cmbDept.DataBindings.Add(New System.Windows.Forms.Binding("Tag",
dsDepts, "Department.DeptID"))


An unhandled exception of type 'System.ArgumentException' occurred in
system.windows.forms.dll

Additional information: Cannot create a child list for field
Department.

It does not work. I do not understand what the problem is.

But thanks Kevin.

Poonam
 
R

Raj Prakash

Did you fill the dataset?
DataAdapterObject.Fill(DataSetObject)

Hope this helps...
Raj Prakash
 
P

Poonam

I did that. But still not getting there. I get errors in the display
member and value member properties.
Thanks,
Poonam


Dim pxy As New Channel1.Channel
dsDepts = pxy.getDepartments()
cmbDept.DisplayMember = "DeptName"
cmbDept.ValueMember = "DeptID"
cmbDept.DataSource = dsDepts.Tables("Department")



getDepartments webmethod is as follows:

<WebMethod()> _
Public Function getDepartments() As DataSet
Dim Sql1 As String = "Select * from Department"
Dim ds As DataSet = objDb.getdataset(Sql1)
Return ds
End Function



Public Function getDataSet(ByVal SqlSelect As String) As DataSet
Dim myDataAdapter As New OleDbDataAdapter(SqlSelect,
myConnection)
Dim myDataSet As New DataSet
myDataAdapter.Fill(myDataSet)
ds = myDataSet
Return myDataSet
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top