lookup databinding combobox using stored procedures

G

Guest

I have a lookup table with and ID field and a Description field, and another
table that has its own ID field, the ID field from the lookup table, and
other data.

LookupTable
LookupTable.ID
LookupTable.Description


OtherDataTable
OtherDataTable.ID
OtherDataTable.LookupTableID
OtherDataTable.OtherData

There are stored procedures for SELECT, INSERT, UPDATE, and DELETE that
maniuplate data in the OtherDataTable as well as another set of stored
procedures for the LookupTable.

I need to create a form that shows the details of the OtherDataTable. To
that end I've created a DataSet that contains a DataTable based on the SELECT
stored procedure for the OtherDataTable the DataTable's INSERT, UPDATE, and
DELETE commands have been set to the stored procedures and I can call them
from my code. In the details of the form I would like to use a combo box
that will allow the use to make a selection based upon the list from
LookupTable where the selected item is LookupTable.Description and the
slected value is LookupTable.ID and the LookupTable.ID value is stored in
OtherDataTable.LookupTableID. Of course as the user scrolls through the
OtherDataTable the combo box must display the appropreate selection.
 
N

Nicholas Paldino [.NET/C# MVP]

What you want to do is load the contents of LookupTable into another
data table or something of that nature, and then bind the drop down list to
that (through the DataBindings and DataSource properties). You also have to
set the ValueMember and DisplayMember properties to indicate which column on
the data table should be displayed, and which one should be used as a value.

Once you do that, you can add a binding to the control which binds your
column to the SelectedValue property. When that property changes (when an
item is selected in the list) it will update your data source, and vice
versa.
 
G

Guest

So if I understand correctly I would have code similar to the following:

CB.DataSource = LookupTableDataSet
CB.ValueMember = LookupTable.ID
CB.DisplayMember = LookupTable.Description
CB.DataBindings.Add(?)

I'm however unclear on what I should be putting for the DataBindings.Add.
Would you please reply with some code like response. Thanks!
 

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