This is driving me crazy ...
I have a typed dataset that I created using VS2008. I created an Insert
statement:
"INSERT INTO x (v1, v2, v3, ..., vN) VALUES (?, ?, ?, ... N?)"
Then I add parameters to the Insert command (OleDbCommand BTW, going into an
Access database):
myOldDbCommandInsert.Parameters.Add(new OleDbParameter("columnName",
OleDbType.DBTimeStamp));
myOldDbCommandInsert.Parameters.Add(new OleDbParameter("columnName2",
OleDbType.Char));
....
myOldDbCommandInsert.Parameters.Add(new OleDbParameter("columnNameN",
OleDbType.UnsignedInt));
Now I set my default values:
myOldDbCommandInsert.Parameters["c1"].Value = defaultValue1;
myOldDbCommandInsert.Parameters["c2"].Value = defaultValue2;
....
myOldDbCommandInsert.Parameters["cN"].Value = defaultValueN;
Then I create my data adapter:
OleDbDataAdapter a = new OleDbDataAdapter("SELECT * FROM x", myConn);
Then the dataset:
MyCustomDataSet ds = new MyCustomDataSet();
a.Fill(ds.MyCustomTable);
So far, everything has worked fine up until this point. So now, I simply
want to add rows to MyCustomTable:
SomeLoopWith5ValuesOrWhatever
{
MyCustomDataSet.MyCustomRowA r = (cast)
MyCustomDataSet.MyCustomTable.NewRow();
r.v1 = x;
r.v2 = y;
r.v3 = z;
r.nN = N;
myDataSet.myDataTable.Rows.Add(r);
}
Stepping through the debugger, that appears to do exactly what I expect. I
can see that the table gets the new rows, and they have the correct values.
However, when I do the following:
myDataAdapter.Update(myDataSet, "NameOfCorrectTable");
The correct number of rows are added to the correct table, but they do not
have the new values?!! They are keeping the default values that I set
earlier in my code. Why is my INSERT statement using these default values?
It's been a while since I messed with database stuff.
Thanks.