Microsoft KB Archive/239781

= FIX: Jet Provider Errors When Setting a Field Equal to a Field Containing an Empty String =

Article ID: 239781

Article Last Modified on 5/17/2007

-

APPLIES TO


 * Microsoft Visual Basic 6.0 Learning Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition
 * Microsoft ActiveX Data Objects 2.1
 * Microsoft ActiveX Data Objects 2.1 Service Pack 1

-



This article was previously published under Q239781



SYMPTOMS
When you save a recordset text field containing an empty string to another recordset's field (this assumes both fields allow zero length), you get the following error message:

Errors occurred. '-2147217887 (80040e21)'.



CAUSE
ADO thinks it is dealing with an object instead of a property.



RESOLUTION
This error does not occur if the value property is specified when setting the contents of one field equal to the contents of another field. ADO needs specific directions to let it know that you are dealing with a property and not an object. The value property of the field clarifies this.

In addition, changing the cursor location to aduseserver solves this problem.



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

This bug was corrected in ADO 2.5 and later.

You may download the latest version of Microsoft Data Access Components, which includes ADO, from the following Microsoft Web site:

http://msdn2.microsoft.com/en-us/data/aa937695.aspx



Steps to Reproduce Behavior
 Start a new Standard EXE project. Form1 is added by default. From the Project menu, click References, and select the Microsoft ActiveX Data Objects and '''Microsoft ADO EXT. for DDL and Security'''. Place a CommandButton on the form, Command1.  Place the following code into Form1: Private Sub Command1_Click Dim TheConn As New ADODB.Connection Dim TheCat As New ADOX.Catalog Dim TheCursor As New ADODB.Recordset Dim TheCursor2 As New ADODB.Recordset Dim Tbl As New ADOX.Table Const sDBName = "c:\test.mdb"

' Create new database, with two similar tables MyTable and MyTable2 On Error Resume Next Kill sDBName On Error GoTo 0

TheCat.Create "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + sDBName Tbl.Name = "MyTable" Tbl.Columns.Append "Field1", adVarWChar, 20 Tbl.Columns.Append "id", adInteger TheCat.Tables.Append Tbl TheCat.Tables("MyTable").Columns("Field1").Properties("JET OLEDB:Allow Zero Length") = True Set Tbl = New Table Tbl.Name = "MyTable2" Tbl.Columns.Append "Field1", adVarWChar, 20 Tbl.Columns.Append "id", adInteger TheCat.Tables.Append Tbl TheCat.Tables("MyTable2").Columns("Field1").Properties("JET OLEDB:Allow Zero Length") = True TheConn.CursorLocation = adUseClient TheConn.Provider = "Microsoft.Jet.OLEDB.4.0" TheConn.Open sDBName TheConn.Execute "INSERT INTO MyTable (ID, Field1) VALUES (1, '')" TheConn.Execute "INSERT INTO MyTable2 (ID, Field1) VALUES (2, 'fred')" TheCursor.Open "SELECT * From MyTable WHERE ID = 1", TheConn, adOpenStatic, adLockReadOnly, adCmdText TheCursor2.Open "SELECT * From MyTable2 WHERE ID = 2", TheConn, adOpenDynamic, adLockPessimistic, adCmdText TheCursor2("Field1") = TheCursor("Field1") ' get error here       'comment the above line and uncomment the line below to eliminate this error 'TheCursor2("Field1").value = TheCursor("Field1").value ' get error here TheCursor2.Update End Sub  Run the project and click Command1.</li></ol>

Additional query words: -2147217887 (80040e21)

Keywords: kbado250fix kbado260fix kbbug kbdatabase kbdatabinding kbfix kbmdacnosweep KB239781

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.