InsertCommand fails because ?

I'm using anOleDbDataAdapter to insert rows into an Access database. I set up the InsertCommand to update 8 fields and everything worked fine. Then I added a 9th field and I got the error message:

"An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system.data.dll"

I tried going back to 8 fields, but I replaced one of the 8 fields with the 9th field. This also worked fine, so it seems that I must be running into some kind of size limitation rather than a problem with a particular database column.

I also tried using anOleDbCommandBuilder to provide the InsertCommand. The CommandBuilder-created command got the same error that I did when I created the InsertCommand myself.

I have double-checked several times and I am quite certain that there are no typos in the command text.

Any ideas anybody? Thanks in advance for your help!

[929 byte] By [MylesR] at [2008-2-4]
# 1
What's the actual stack trace and message of the Exception?
DavidM.Kean at 2007-8-21 > top of Msdn Tech,.NET Development,.NET Framework Data Access and Storage...
# 2

After struggling with this for some time, I came up with the following problems, all of which produce this same, particularly unhelpful error message. Is there a way to get more descriptive error messages when a SQL statement fails?

Possible reasons for error: An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system.data.dll” on a database insert/update are:

a. An inserted value is larger than the maximum defined size for the field in the database definition.

b. Single quote(s) in the data.

c. The parameters that were added to the command object are not in the same order as they appear in the insert (or update?) command. (I assume that this could also apply to update commands.)

d. The new record represents a duplicate key value for a field that does not allow duplicates.

e. The new record does not contain a value for a field that requires a value.

MylesR at 2007-8-21 > top of Msdn Tech,.NET Development,.NET Framework Data Access and Storage...
# 3

I put the statement in a try/catch block, but it didn't catch... Whoops! Wrong exception type specified in the catch statement. See my other response for a list of the errors that I ran into. Thanks for responding!

MylesR at 2007-8-21 > top of Msdn Tech,.NET Development,.NET Framework Data Access and Storage...
# 4
The error 'An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system.data.dll' is a Visual Studio debugging error, try catching an OleDbException and displaying the message, like so:


try
{
// Execute query here
}
catch (OleDbException ex)
{
System.Windows.Forms.MessageBox.Show(ex.ToString());
}

DavidM.Kean at 2007-8-21 > top of Msdn Tech,.NET Development,.NET Framework Data Access and Storage...

.NET Development

Site Classified