INSERT Problem

  • Thread starter Thread starter Tom
  • Start date Start date
T

Tom

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.
 
Tom said:
This is driving me crazy ...

I have a typed dataset that I created using VS2008. I created an
Insert statement:
There was no way for you to know it (except maybe by browsing through some
of the previous questions in this newsgroup before posting yours - always a
recommended practice) , but this is a classic (COM-based) ADO newsgroup.
ADO.Net bears very little resemblance to classic ADO so, while you may be
lucky enough to find a dotnet-knowledgeable person here who can answer your
question, you can eliminate the luck factor by posting your question to a
group where those dotnet-knowledgeable people hang out. I suggest
microsoft.public.dotnet.framework.adonet.

Oops, I've just noticed you crossposted to several groups. I'm replying from
the data.ado group.The only relevant group you chose was the dotnet group.
They might be able to help you there. if not, try the adonet group.
 

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

Back
Top