Cannot set Empty to Date field using Oracle, SQL Provider, or Kagera (247202)



The information in this article applies to:

  • Microsoft Visual Basic Professional Edition for Windows 5.0
  • Microsoft Visual Basic Professional Edition for Windows 6.0
  • Microsoft Visual Basic Enterprise Edition for Windows 5.0
  • Microsoft Visual Basic Enterprise Edition for Windows 6.0
  • Microsoft Data Access Components 2.1 SP2
  • 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:
Run-time error '-2147217887(8004e21)': Errors Occurred
Under MDAC 2.5 or later, you receive this message:
Run-time error '-2147217887(8004e21)': Multiple-step operation generated errors. Check each status value.

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

  1. Start Visual Basic.
  2. Create a Standard EXE Project and Reference Microsoft ActiveX Data Objects Library 2.x.
  3. 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
    					

Modification Type:MinorLast Reviewed:11/22/2005
Keywords:kbDatabase kbprb KB247202