Fog Creek Software
Discussion Board




Welcome! and rules

Joel on Software

strange ADO.NET updating problem

I use the following code to add data to my database:

DataTable table=dataSet11.Tables[0];
        
DataRow newRow = table.NewRow();

newRow["id_prod"]=25;

table.Rows.Add(newRow);

oleDbDataAdapter1.Update(table);


However, at the last line, an exception is thrown:

An unhandled exception of type 'System.InvalidCastException' occurred in system.data.dll

Additional information: Invalid cast from System.Int32 to System.Guid.


This is very strange, because the id_prod field is numeric, and I can manually add data in Access, and everything is ok.

The data adapter and dataset were generated using drag & drop from server explorer, and no error appeared.

Very strange!

Scott
Sunday, June 22, 2003

I have tried adding a dataSet11.AcceptChanges() call, before the update call. I also tried calling the Fill method before the whole thing, to load the data.

It doesn't throw exceptions anymore, but the Access database is still NOT updated!!!

All I want is to simply insert records into the access database which is stored on disk!

Scott
Sunday, June 22, 2003

I have solved the problem.

The thing happened because I have created the database, then created the components in the IDE, then changed some column types, then wrote the code...

I have re-created the components in the IDE, and the database updates just fine!

Scott
Sunday, June 22, 2003

Yes, when you create the components in the IDE, it looks into the database for field types and then hard-wires those into the code.

If you need to support a table that might actually change, look into the OleDbCommandBuilder, which will build the commands for updating at runtime instead of design time. Of course, there's a performance penalty to this.

Mike Gunderloy
Monday, June 23, 2003

*  Recent Topics

*  Fog Creek Home