PRB: Cannot Set Empty to Date Field using Oracle, SQL Provider, or Kagera
ID: Q247202
|
The information in this article applies to:
-
Microsoft Visual Basic Professional and Enterprise Editions for Windows, versions 5.0, 6.0
-
Microsoft Data Access Components versions 2.1 SP2, 2.5
SYMPTOMS
If one tries 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 Occured
Under MDAC 2.5 one receives 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:
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 supresses 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 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
REFERENCES
© Microsoft Corporation 1999, All Rights Reserved.
Contributions by Matthew Hofacker, Microsoft Corporation
Additional query words:
Keywords : kbGrpVBDB kbGrpMDAC kbDSupport kbADO210sp2 kbMDAC210SP2 kbADO250
Version : WINDOWS:2.1 SP2,2.5,5.0,6.0
Platform : WINDOWS
Issue type : kbprb