Binding a combobox to a sql ce/mobile table through code

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi guys,
I'm looking to bind a combobox to a table in my database, but i seem to be
missing a step. What would i use as a datasource? And how would i derive that
from an sqlceconnection?
 
Ok, so far I've got code that looks like this:

Dim cmd As SqlCeCommand = m_LocalConn.CreateCommand
cmd.CommandText = "SELECT * FROM " & m_DataTable
Dim ds As New DataSet
Dim adp As SqlCeDataAdapter = New SqlCeDataAdapter(cmd)

'Fill the dataset
adp.Fill(ds)

'Bind data to combobox
cbo.DataSource = ds
cbo.DisplayMember = m_DataColumn
cbo.ValueMember = m_CodeColumn


The dataset gets populated correctly, but i have problems when i try to set
the DisplayMember and ValueMember properties of cbo (my combobox) I get
SystemArguement Exceptions.. Any ideas?

ds is structured like this

Table
OtherColumn
DataColumn
CodeColumn
MoreColumns
 
These should be strings with the names of the properties (fields) to use
e.g.

'Bind data to combobox
cbo.DataSource = ds
cbo.DisplayMember = "CustomerName"
cbo.ValueMember = "CustomerID"

Peter
 
.... in addition, instead of:

cbo.DataSource = ds

must be

cbo.DataSource = ds.Tables(0)
 
m_DataColumn and m_CodeColumn are both strings (in the code i was using one
was "Name" and the other was "Code")
 
Back
Top