BUG: DataColumn.MaxLength property is not set for strongly typed DataSets (317175)



The information in this article applies to:

  • Microsoft ADO.NET (included with the .NET Framework)
  • Microsoft ADO.NET (included with the .NET Framework 1.1)
  • Microsoft Visual Studio .NET (2002), Enterprise Developer Edition
  • Microsoft Visual Studio .NET (2003), Enterprise Developer Edition

This article was previously published under Q317175

SYMPTOMS

If you create a strongly typed DataSet, the DataColumn.MaxLength property is not set.

RESOLUTION

To resolve this issue, use the FillSchema method to get the DataColumn.MaxLength property, or set the MissingSchemaAction property to AddWithKey.

STATUS

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

MORE INFORMATION

Steps to Reproduce the Behavior

  1. Open Visual Studio .NET, and then create a new Microsoft Visual Basic .NET Windows Application.
  2. Add a command button to Form1.
  3. Create a typed DataSet to the Northwind database. Use "SELECT * FROM customers" as the SQL statement.
    For additional information, click the article number below to view the article in the Microsoft Knowledge Base:

    315678 HOW TO: Create and Use a Typed DataSet in .NET

  4. Copy and paste the following code into the button1_click event:
            SqlDataAdapter1.Fill(DataSet11, "customers")
            'SqlDataAdapter1.FillSchema(DataSet11, SchemaType.Mapped)
            MessageBox.Show(DataSet11.Customers.CustomerIDColumn.MaxLength)
    					
  5. Save the project, and then run the project.
  6. Notice that the MessageBox displays -1.
  7. Uncomment the FillSchema line of code, and then run the project.
  8. Notice that the correct value appears.
NOTE: Instead of FillSchema, you can use the following before the Fill method is called:
SqlDataAdapter1.MissingSchemaAction = MissingSchemaAction.AddWithKey 
NOTE: Because FillSchema requires an additional trip to the database to get the Schema information, using FillSchema can affect performance.

Modification Type:MinorLast Reviewed:3/10/2006
Keywords:kbtshoot kbvs2002sp1sweep kbbug kbSqlClient kbSystemData KB317175 kbAudDeveloper