J
Joe Keller
Hello,
I have a combo box that gets it lookup values from table A but is bound to
table B. When I pull up my form and navigate through the records, the
records are read and displayed correctly in all of my fields, including the
combo box. However, when I change the value of what is shown in the combo
box, the changed value does not "stick". If I navigate away and then back
to the record I just changed the combo box value has reverted back to its
old value. The text box controls on my form properly keep their changed
values as one would expect.
Could someone tell me if I'm doing something wrong here? I'm not getting
any errors at compile or run-time. The only thing I'm doing out of the
"norm" is actually saving the text value of the combo box to the main table
from which it is bound to (the main table expects a text value, not an
integer).
Here's the relevant snippet of code:
-----------------------------------------------------
comboBox1.Visible=false;
DataTable dt = new DataTable("tblCategoryType");
DataTable dt2 = new DataTable("tblInventoryItem");
myCommand.CommandText = "SELECT sCategoryTypeID FROM tblCategoryType";
SqlCeDataAdapter da;
da = new SqlCeDataAdapter(myCommand);
da.Fill(dt);
myCommand.CommandText = "SELECT * FROM tblInventoryItem";
SqlCeDataAdapter da2;
da2 = new SqlCeDataAdapter(myCommand);
da2.Fill(dt2);
comboBox1.DataSource=dt;
comboBox1.DisplayMember="sCategoryTypeID";
comboBox1.ValueMember="sCategoryTypeID";
comboBox1.DataBindings.Add("Text", dt2, "sCategoryTypeID");
comboBox1.Visible=true;
-----------------------------------------------------
The table DDL's look like the following:
-----------------------------------------------------
/* tblCategoryType*/
CREATE TABLE tblCategoryType (sCategoryTypeID nVarChar(25) NOT NULL PRIMARY
KEY)
/* tblInventoryItem */
CREATE TABLE tblInventoryItem(lInventoryItemID int IDENTITY PRIMARY KEY,
sItemName nVarChar(30) NOT NULL, sItemDescription nVarChar(25) NULL,
sCategoryTypeID nVarChar(25) NOT NULL REFERENCES tblCategoryType
(sCategoryTypeID))
-----------------------------------------------------
Any help is appreciated!
Thanks,
Joe
I have a combo box that gets it lookup values from table A but is bound to
table B. When I pull up my form and navigate through the records, the
records are read and displayed correctly in all of my fields, including the
combo box. However, when I change the value of what is shown in the combo
box, the changed value does not "stick". If I navigate away and then back
to the record I just changed the combo box value has reverted back to its
old value. The text box controls on my form properly keep their changed
values as one would expect.
Could someone tell me if I'm doing something wrong here? I'm not getting
any errors at compile or run-time. The only thing I'm doing out of the
"norm" is actually saving the text value of the combo box to the main table
from which it is bound to (the main table expects a text value, not an
integer).
Here's the relevant snippet of code:
-----------------------------------------------------
comboBox1.Visible=false;
DataTable dt = new DataTable("tblCategoryType");
DataTable dt2 = new DataTable("tblInventoryItem");
myCommand.CommandText = "SELECT sCategoryTypeID FROM tblCategoryType";
SqlCeDataAdapter da;
da = new SqlCeDataAdapter(myCommand);
da.Fill(dt);
myCommand.CommandText = "SELECT * FROM tblInventoryItem";
SqlCeDataAdapter da2;
da2 = new SqlCeDataAdapter(myCommand);
da2.Fill(dt2);
comboBox1.DataSource=dt;
comboBox1.DisplayMember="sCategoryTypeID";
comboBox1.ValueMember="sCategoryTypeID";
comboBox1.DataBindings.Add("Text", dt2, "sCategoryTypeID");
comboBox1.Visible=true;
-----------------------------------------------------
The table DDL's look like the following:
-----------------------------------------------------
/* tblCategoryType*/
CREATE TABLE tblCategoryType (sCategoryTypeID nVarChar(25) NOT NULL PRIMARY
KEY)
/* tblInventoryItem */
CREATE TABLE tblInventoryItem(lInventoryItemID int IDENTITY PRIMARY KEY,
sItemName nVarChar(30) NOT NULL, sItemDescription nVarChar(25) NULL,
sCategoryTypeID nVarChar(25) NOT NULL REFERENCES tblCategoryType
(sCategoryTypeID))
-----------------------------------------------------
Any help is appreciated!
Thanks,
Joe