Microsoft Knowledge Base Email Alertz

KBAlertz.com: After you use the

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]

Search KbAlertz

Advanced Search

Webmasters
Put kbAlertz on your website.
[ Click Here for more! ]





ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
The ad says 3 - but KBAlertz referrals get
** SIX MONTHS FREE **


Bug Tracking Software
For bug tracking software or defect tracking software or issue tracking software, visit Axosoft.


Community Site



We Send hundreds of thousands of emails using ASP.NET Email



Expert Web Design & Graphic Design
Design44.com

ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
The ad says 3 - but KBAlertz referrals get
** SIX MONTHS FREE **




Mentioned In








Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks




Article ID: 310373 - Last Review: May 13, 2007 - Revision: 2.6

The DataAdapter.Fill method does not set all of the properties of the DataTable and DataColumn objects

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

On This Page

SYMPTOMS

After you use the DataAdapter.Fill method, various properties of the DataTable and DataColumn objects (such as primary keys, auto increment fields, nullable fields, unique indexes, and so on) are not set.

CAUSE

The DataAdapter object is optimized for read-only scenarios by default. The Fill method only retrieves the amount of schema that is necessary to display the data. You must take extra steps to obtain the additional schema that are necessary to update or validate an object.

RESOLUTION

To obtain additional information about the DataSet object, use one of the following methods:
  • Call the DataAdapter.FillSchema method to obtain extended schema information.
  • Set DataAdapter.MissingSchemaAction to MissingSchemaAction.AddWithKey before you call the Fill method.
For additional information about when to use the FillSchema method and MissingSchemaAction property, click the article number below to view the article in the Microsoft Knowledge Base:
310128  (http://kbalertz.com/Feedback.aspx?kbNumber=310128/ ) When to use FillSchema and MissingSchemaAction

MORE INFORMATION

Steps to reproduce the behavior

  1. Start Microsoft Visual Studio .NET.
  2. Create a new Windows Application project in Visual Basic .NET. Form1 is added to the project by default.
  3. Make sure that your project contains a reference to the System.Data namespace.
  4. Place a Button control and a DataGrid control on Form1.
  5. Change the Name property of the button to btnTest and the Text property to Test.
  6. Use the Imports statement on the System and System.Data namespaces so that you are not required to qualify declarations in those namespaces later in your code. Add the following code to the "General Declarations" section of Form1:
    Imports System
    Imports System.Data.OleDb
    Imports System.Data.SqlClient
    					
  7. Add the following code in the Code window after the "Windows Form Designer generated code" region:
        Private Sub btnTest_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles btnTest.Click
            Dim myConnString As String = _
                    "User ID=sa;password=sa;Initial Catalog=Northwind;Data Source=myServer"
            Dim ds As New DataSet()
            Dim con As New SqlConnection(myConnString)
            Dim daCust As New SqlDataAdapter("Select * From Customers", con)
            'Uncomment either of the following two lines to obtain additional schema information.
            'daCust.MissingSchemaAction = MissingSchemaAction.AddWithKey
            'daCust.FillSchema(ds, SchemaType.Source, "Cust")
            daCust.Fill(ds, "Cust")
    
            DataGrid1.DataSource = ds
            DataGrid1.DataMember = "Cust"
    
            Dim colArr() As DataColumn
            colArr = ds.Tables(0).PrimaryKey
            If colArr.Length.ToString() = 0 Then
                MessageBox.Show("No Primary Key is defined.")
            End If
    
            Dim i As Integer
            For i = 0 To colArr.GetUpperBound(0)
                MessageBox.Show("Primary Key : " & colArr(i).ColumnName)
            Next i
        End Sub
    					
  8. Modify the connection string (myConnString) as appropriate for your environment.
  9. Save your project. On the Debug menu, click Start to run your project.
  10. Click Test. Notice that you cannot retrieve the primary key information from the table.
  11. Uncomment the code to either set MissingSchemaAction or use FillSchema, and then click Test again. Notice that the primary key information is retrieved properly.

REFERENCES

For more information on ADO.NET objects and syntax, see the following Microsoft .NET Framework Software Development Kit (SDK) documentation or MSDN Online:
Accessing Data with ADO.NET
http://msdn2.microsoft.com/en-us/library/e80y5yhx(vs.71).aspx (http://msdn2.microsoft.com/en-us/library/e80y5yhx(vs.71).aspx)

APPLIES TO
  • Microsoft ADO.NET 2.0
  • Microsoft ADO.NET (included with the .NET Framework)
  • Microsoft Visual Basic .NET 2002 Standard Edition
  • Microsoft Visual Basic .NET 2003 Standard Edition
  • Microsoft Visual Basic 2005
Keywords: 
kbtshoot kbprb kbsqlclient kbsystemdata KB310373
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate

Be the first to leave feedback, to help others about this knowledge base article.

(Optional) Name

(Optional) Public URL Or Email

Comments
No HTML -- Text Only Please