olddbdataadapter updatecommand parameter

R

ramsey

I've got my DataSet built (and broken the connection), I've updated it
(changes only), and now I'm ready to send back the changes. Here's what I
tried:

private void UpdateDatabase()

{

OleDbCommand _update = new OleDbCommand(

"UPDATE tblDocuments SET InspDate=?, ChildDOB=?, ChildBlSampDate=? WHERE
DocumentID=?");

_update.Parameters.Add("InspDate", OleDbType.DBDate).SourceVersion =
DataRowVersion.Current;

_update.Parameters.Add("ChildDOB", OleDbType.DBDate).SourceVersion =
DataRowVersion.Current;

_update.Parameters.Add("ChildBlSampDate", OleDbType.DBDate);

_update.Parameters.Add("DocumentID", OleDbType.Char, 8);

_db.Open();

_update.Connection = _db;

_da.UpdateCommand = _update;

_da.Update(_dsBox, _dsBox.Tables[0].TableName );

_db.Close();

_dsBox.AcceptChanges();

}

Here's the error I get:

System.InvalidOperationException was unhandled
Message="Parameter[0] '' has no default value.\r\nParameter[1] '' has no
default value.\r\nParameter[2] '' has no default value.\r\nParameter[3] ''
has no default value.\r\n"
Source="System.Data"
StackTrace:
at
System.Data.Common.DbDataAdapter.UpdatedRowStatusErrors(RowUpdatedEventArgs
rowUpdatedEvent, BatchCommandInfo[] batchCommands, Int32 commandCount)


Question: Why do I want a default value when the original data has values?
 
W

W.G. Ryan - MVP

The third and forth [2][3]params don't appear to have value set unless
they're being set elsewhere. The value for the first may be a null.

As an aside, (this has nothing to do with your problem, just a general FYI),
the adapter will open and close the connection for you so you don't have to.
If you're opening it manually though, make sure you use a finally block to
close it or use a Using statement. Also, each update/insert/delete calls
AcceptChanges on the row individually, so you don't need to call it at the
end. It won't hurt anything but it's not necessary.
 
R

ramsey

Ok. I is MAJORLY dumb.

When I generated the UPDATE command (using command builder) I got a command
that included all the fields in the dataset, not only those that 'I' know
can be updated. There are also a major WHERE clause which also includes
every field in the world.

Question: I loaded the schema when I did the select to load the dataset.
That SHOULD have included the key, the document id. Shouldn't that be all I
need to match in the WHERE clause?
 

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