FIX: You cannot insert empty string into Memo, Text, nText, or Blob columns (316323)



The information in this article applies to:

  • Microsoft ADO.NET (included with the .NET Framework)
  • Microsoft Visual Basic .NET (2002)

This article was previously published under Q316323
This article refers to the following Microsoft .NET Framework Class Library namespace:
  • System.Data.OleDb

SYMPTOMS

When you try to insert an empty string into Memo, Text, nText or Blob columns by using the OLE DB .NET data provider, you receive the following exception:
An unhandled exception of type 'System.InvalidOperationException' occurred in system.data.dll
If you handle this exception within a try-catch block, you receive the following information:
System.InvalidOperationException
System.Data.OleDb.OleDbException: Multiple-Step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done.

RESOLUTION

To work around this problem:
  • For strings, insert a space that has a length greater than zero (such as " "), instead of using an empty string.
  • If the database has an Allow Nulls setting, select Allow Nulls for the columns in the database, and treat nulls as empty strings.

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 Microsoft ADO.NET (included with the .NET Framework 1.1), and Microsoft Visual Basic .NET (2003).

MORE INFORMATION

Steps to Set Up the Database

  1. Create a table "Test" in your Microsoft Access database.
  2. Add the following two fields to the database:

    "Fld1" Data Type = "Text"
    "Fld2" Data Type = "Memo", Required="Yes", AllowZeroLength="Yes"

  3. Make Fld1 the primary key.
  4. Save the changes and close the database.

Steps to Reproduce the Problem

  1. Start Visual Studio .NET.
  2. Create a new Microsoft Windows application in Visual Basic .NET.
  3. Make sure that your project contains a reference to the System.Data namespace.
  4. Place a command button on Form1. Change the Name property of the button to "btnTest" and the Text property to "Test".
  5. Use the Imports statement on the System and System.Data namespaces, so that you do not have to qualify declarations in those namespaces later in your code. Add the following to the General Declarations section of Form1, as follows:
    Imports System
    Imports System.Data.OleDb
    					
  6. Paste the following code in the code window, after the region "Windows Form Designer generated code":
    Private Sub btnTest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTest.Click
        Try
            Dim myConnString As String = _
                    "Provider = Microsoft.Jet.Oledb.4.0;Data Source=c:\nwind1.mdb;"
            Dim mySql As String = "SELECT * FROM Test"
            Dim ds As New DataSet()
            Dim conn As New OleDbConnection(myConnString)
            conn.Open()
    
            Dim da As New OleDbDataAdapter(mySql, conn)
            da.MissingSchemaAction = MissingSchemaAction.AddWithKey
            da.Fill(ds, "Test")
    
            Dim dr As DataRow
            dr = ds.Tables("Test").NewRow
            dr("Fld1") = "1111"
            dr("Fld2") = ""
            ds.Tables(0).Rows.Add(dr)
    
            Dim cb As New OleDbCommandBuilder(da)
            da.Update(ds, "Test")
    
            conn.Close()
        Catch ex As Exception
            MessageBox.Show(ex.ToString)
        End Try
    End Sub
    					
  7. Modify the connection string (myConnString) as appropriate for your environment.
  8. Save your project. On the Debug menu, click Start to run your project.
  9. Click Test.

    Notice that an exception is generated when you attempt to update.

REFERENCES

For more information about ADO.NET objects and syntax, see the following Microsoft .NET Framework SDK documentation: For additional information about ADO.NET, click the article number below to view the article in the Microsoft Knowledge Base:

313590 INFO: Roadmap for ADO.NET


Modification Type:MinorLast Reviewed:9/15/2005
Keywords:kbvs2002sp1sweep kbfix kbbug kbSystemData KB316323