Microsoft Knowledge Base Email Alertz

KBAlertz.com: If you create 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: 308625 - Last Review: February 12, 2007 - Revision: 1.4

The enumerated DataReader returns incomplete information for batch queries that have different schemas

This article was previously published under Q308625

On This Page

SYMPTOMS

If you create the DBEnumerator object on batch queries with different schemas, DBEnumerator returns incorrect or incomplete information. For example, if you run a batch query that contains two SELECT statements that return different schemas, the second statement may not return the entire schema.

CAUSE

This problem occurs because, by design, you can only use the DBEnumerator object with one result set.

RESOLUTION

To work around this behavior, obtain a DBEnumerator for each result set, and then call the NextResult method of a .NET data provider's DataReader object.

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, and add a reference to this namespace if it does not.
  4. Place a Button control on Form1. Button1 is added by default.
  5. Use the Imports statement on the System, System.Data, System.Data.Common, System.Collections and System.Data.SqlClient namespaces so that you are not required to qualify declarations in those namespaces later in your code.
    Imports System
    Imports System.Data
    Imports System.Data.Common
    Imports System.Collections
    Imports System.Data.SqlClient
    					
  6. In the Code window, add the following code after the "Windows Form Designer generated code" region:
    Private Sub Button1_Click(ByVal sender As System.Object, _
       ByVal e As System.EventArgs) Handles Button1.Click
    
       Dim cn As New SqlConnection( _
           "server=servername;uid=sa;pwd=;database=Northwind")
       cn.Open()
       Dim cm As New System.Data.SqlClient.SqlCommand( _
           "SELECT FirstName FROM Employees WHERE EmployeeId = 1;" & _
           "SELECT FirstName, LastName FROM Employees WHERE " & _
           "EmployeeId = 2", cn)
    
       Dim dr As System.Data.SqlClient.SqlDataReader
       dr = cm.ExecuteReader
    
       Dim rEnum As System.Data.Common.DbEnumerator = _
          CType(CType(dr, System.Collections.IEnumerable).GetEnumerator(), _
          DbEnumerator)
    
       Debug.WriteLine("rEnum.MoveNext = " & rEnum.MoveNext())
    
       Dim record1 As DbDataRecord = (CType(rEnum.Current, DbDataRecord))
       Debug.WriteLine(record1.FieldCount)
       Debug.WriteLine(" The number of fields in this dataRecord " & _
           record1.FieldCount)
       Debug.WriteLine("The value of the first field is " & _
           record1.GetValue(0))
    
       dr.NextResult()
    
       rEnum.MoveNext()
    
       Dim record2 As DbDataRecord = (CType(rEnum.Current, DbDataRecord))
    
       ' Note that the DataRecord only displays a field count of 1,
       ' which is incorrect
       Debug.WriteLine("The number of fields in this DataRecord " & _
           record2.FieldCount)
       Debug.WriteLine("The value of the first field is = " & _
           record2.GetValue(0))
    
       dr.Close()
       cn.Close()
    End Sub
    					
  7. Modify the connection string as appropriate for your environment.
  8. Save your project. On the Debug menu, click Start to run your project.
  9. Click Button1. Press the CTRL+ALT+O key combination to view the Output window. Notice that the number of fields in the second DataRecord (record2) is 1, which is incorrect, and the LastName field is missing.
  10. To work around this behavior, add LastName to the SELECT statement to change the schema of the first query so that it matches the second query. Notice that the number of fields is correct.

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 .NET Framework 1.1
Keywords: 
kbprb kbreadme kbsqlclient kbsystemdata KB308625
       

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