Article ID: 247202
Article Last Modified on 11/22/2005
APPLIES TO
- Microsoft Visual Basic 5.0 Professional Edition
- Microsoft Visual Basic 6.0 Professional Edition
- Microsoft Visual Basic 5.0 Enterprise Edition
- Microsoft Visual Basic 6.0 Enterprise Edition
- Microsoft Data Access Components 2.1 Service Pack 2
- Microsoft Data Access Components 2.5
- Microsoft Data Access Components 2.6
- Microsoft Data Access Components 2.7
This article was previously published under Q247202
SYMPTOMS
If you try to store the Visual Basic keyword Empty to an ADODB Record column based on Date type field as in the following code
rs("fDate") = Empty
it causes this error:
Under MDAC 2.5 or later, you receive this message:
RESOLUTION
If it is necessary to re-initialize a date type field back to a blank value, cancel the AddNew operation using CancelUpdate and re-issue the AddNew method.
STATUS
Microsoft is currently researching this problem and will post new information here as it becomes available.
MORE INFORMATION
This occurs with the Microsoft OLE DB Provider for:
- Oracle
- SQL Server
- ODBC
This does not occur if the OLE DB Provider for Jet database engine is used. When Empty is stored to an ADODB Recordset column based on a Jet database engine DateTime field there is a date and time value entered into the field, however the Jet database engine suppresses the date portion. This is different behavior than with Integer and Character type columns. If Empty is stored to an Integer column, a Zero is stored to the Row regardless of the Provider and if it is a Character type field an Empty string ID stored.
Steps to reproduce the behavior
- Start Visual Basic.
- Create a Standard EXE Project and Reference Microsoft ActiveX Data Objects Library 2.x.
Paste the following code into the default form, making sure to modify the connection string for your particular server name:
Private Sub Form_Load() dim cn as new adodb.connection dim rs as new adodb.recordset 'Select desired Connection, ConnectionString, and Data Source 'Make necessary changes to the ConnectionString cn.Open "Provider=SQLOLEDB;User ID=<>;Password=<>;Initial Catalog=pubs;Data Source=<>" 'cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=<>;" 'cn.Open "Provider=MSDAORA;User ID=<>;PASSWORD=<>;Data Source=dseoracle8;" On Error Resume Next cn.Execute "drop table batchtest" On Error GoTo 0 'If Jet or SQL use this statement cn.Execute "create table batchtest (id int primary key," & _ "fstring varchar(50) NOT NULL," & _ "fnumber int NOT NULL," & _ "fdate datetime NOT NULL)" 'If ORACLE use this statement 'cn.Execute "create table batchtest (id int primary key," & _ "fstring varchar(50) NOT NULL," & _ "fnumber int NOT NULL," & _ "fdate date NOT NULL)" rs.Open "select * from batchtest", cn, adOpenStatic, adLockBatchOptimistic rs.AddNew rs.Fields("id").Value = 1 rs.Fields("fstring").Value = "XXXXX" rs.Fields("fnumber").Value = 999 rs.Fields("fdate").Value = #3/3/1999# rs.Update rs.AddNew rs.Update rs.AddNew rs.Fields("id").Value = 2 rs.Fields("fstring").Value = Empty rs.Fields("fnumber").Value = Empty 'Error occurs here rs.Fields("fdate").Value = Empty rs.Update End Sub
Keywords: kbdatabase kbprb KB247202