Hi,
I have a DB-table 'AirplaneTypes' that has to 2 fields that form the primary
key :
'at_name' and 'at_model'
both in the DB defined as type : char 15
MyWinform client :
void Form_Load(...) {
// m_dsAirplaneTypes1 is the DataSet
DataTable myTable = m_dsAirplaneTypes1.AirplaneTypes;
txtName.DataBindings.Add("Text", myTable, "at_name");
==> when this databind is executed will an exception be thrown from
the moment I perform an 'AcceptChanges' on my DataSet (see
below)
If this binding is not executed at Form_Load() :
no exception thrown by 'AcceptChanges' (???)
// Following DataBindings don't create any problems (only the
previous??)
txtModel.DataBindings.Add("Text", myTable, "at_model");
txtLength.DataBindings.Add("Text", myTable, "at_length");
}
Below is the buttonInsert-click event that will generate an exception, not
after I
enter values for the first time :
txtName.Text = "1" txtModel.Text = "1" txtLength.Text = "1"
but when entering values the 2nd time :
txtName.Text = "2" txtModel.Text = "2" txtLength.Text= "2"
void btnInsert_Click(...) {
m_currentRow = m_dsAirplaneTypes1.AirplaneTypes.NewRow();
// Edit the fields
m_currentRow["at_name"] = txtName.Text.Trim();
m_currentRow["at_model"] = txtModel.Text.Trim();
m_currentRow["at_length"] = txtLength.Text.Trim();
// Add to DataSet
m_dsAirplaneTypes1.AirplaneTypes.Rows.Add(m_curren tRow);
// Add to DB
int n = sqlDataAdapter1.Update(m_dsAirplaneTypes1, "AirplaneTypes");
if (n > 0)
m_dsAirplaneTypes1.AirplaneTypes.AcceptChanges();
==> EXCEPTION thrown when I execute the 2nd time (and I enter
different values !!)
"Column 'at_name, at_model' is constrained to be unqiue.
Value '2, 2' is already present"
BUT THE DATA HAS BEEN ENTERED IN THE DB CORRECTLY !
So 'sqlDataAdapter1.Update() ' performs well.
}
Any help GREATLY appreciated !!
Chris