Tuesday, July 27, 2004

Problems with updates using OleDbConnection in VS.Net when dates are present.

In my last post I forgot to mention, if you're having problems updating something and you're connecting to Access or another database using OleDb, do yourself a favor and edit the autogenerated code that handles record creation and deletes.

In your oleDbUpdateCommand section, you'll find that date fields are handled with the attribute

System.Data.OleDb.OleDbType.DBDate
 
Instead switch the "DBDate" to "Date" and the update will actually function, like

System.Data.OleDb.OleDbType.Date
 
It is safe to do a global search and replace on this, as the other areas that use DBDate without problems aren't affected by the change.

This reminds me of all the trouble you have to go through with date delimiters when you're working with old ADO in Access and SQL Server, that is, using "#" or " ' " respectively.

No comments:

Post a Comment