vb.net qr code generator free Try It Out: Handling Multiple Result Sets in Visual Basic .NET

Creator Data Matrix ECC200 in Visual Basic .NET Try It Out: Handling Multiple Result Sets

Try It Out: Handling Multiple Result Sets
Drawing ECC200 In Visual Basic .NET
Using Barcode drawer for VS .NET Control to generate, create ECC200 image in .NET applications.
www.OnBarcode.com
DataMatrix Recognizer In Visual Basic .NET
Using Barcode recognizer for VS .NET Control to read, scan read, scan image in VS .NET applications.
www.OnBarcode.com
In this example, you ll use NextResult() to process multiple result sets. 1. Add a new Visual Basic Console Application project named MultipleResults to your 12 solution. Rename Module1.vb to MultipleResults.vb. 2. Replace the code in MultipleResults.vb with the code in Listing 12-6. Listing 12-6. MultipleResults.vb Imports System Imports System.Data Imports System.Data.SqlClient Module MultipleResults Sub Main() Dim connstring As String = _ ("Data Source=.\sqlexpress;" & _ "Integrated Security=True;" & _ "database=northwind")
Painting EAN128 In VB.NET
Using Barcode drawer for VS .NET Control to generate, create GTIN - 128 image in .NET applications.
www.OnBarcode.com
Print Barcode In VB.NET
Using Barcode printer for VS .NET Control to generate, create Barcode image in .NET framework applications.
www.OnBarcode.com
CHAPTER 12 s USING DATA READERS
PDF-417 2d Barcode Creator In Visual Basic .NET
Using Barcode generator for .NET Control to generate, create PDF 417 image in VS .NET applications.
www.OnBarcode.com
Create Linear 1D Barcode In VB.NET
Using Barcode printer for .NET Control to generate, create Linear image in .NET applications.
www.OnBarcode.com
'query1 Dim sql1 As String = "select companyname,contactname " & _ "from customers where " & _ "companyname like 'A%'" 'query2 Dim sql2 As String = "select firstname," & _ "lastname from employees" 'combine queries Dim sql As String = sql1 + sql2 'create connection Dim conn As SqlConnection = New SqlConnection(connstring) Try 'Open connection conn.Open() 'create command Dim cmd As SqlCommand = New SqlCommand(sql, conn) 'create data reader Dim rdr As SqlDataReader = cmd.ExecuteReader Do While rdr.Read() ' Print one row at a time Console.WriteLine("{0} : {1}", rdr(0), rdr(1)) End While Console.WriteLine("".PadLeft(60, "=".ToString)) Loop While rdr.NextResult() Catch e As Exception Console.WriteLine("Error Occurred:" & e.ToString) Finally ' Close connection conn.Close() End Try End Sub End Module 3. Make MultipleResults the startup project, and run it by pressing Ctrl+F5. You should see the results in Figure 12-6.
Make Code 39 Full ASCII In VB.NET
Using Barcode creator for .NET Control to generate, create Code 39 Extended image in VS .NET applications.
www.OnBarcode.com
USPS POSTNET Barcode Generator In Visual Basic .NET
Using Barcode encoder for Visual Studio .NET Control to generate, create Delivery Point Barcode (DPBC) image in .NET applications.
www.OnBarcode.com
CHAPTER 12 s USING DATA READERS
DataMatrix Generation In Java
Using Barcode encoder for Android Control to generate, create ECC200 image in Android applications.
www.OnBarcode.com
DataMatrix Drawer In Java
Using Barcode creator for BIRT Control to generate, create Data Matrix ECC200 image in BIRT applications.
www.OnBarcode.com
Figure 12-6. Handling multiple result sets
PDF-417 2d Barcode Encoder In Java
Using Barcode drawer for Java Control to generate, create PDF 417 image in Java applications.
www.OnBarcode.com
Printing EAN13 In .NET Framework
Using Barcode drawer for ASP.NET Control to generate, create EAN-13 image in ASP.NET applications.
www.OnBarcode.com
How It Works
ANSI/AIM Code 128 Drawer In Java
Using Barcode creation for Android Control to generate, create Code 128B image in Android applications.
www.OnBarcode.com
PDF-417 2d Barcode Creation In .NET
Using Barcode printer for ASP.NET Control to generate, create PDF-417 2d barcode image in ASP.NET applications.
www.OnBarcode.com
This program is essentially the same as the first, DataLooper.cs (Listing 12-1). Here, you define two separate queries and then combine them: 'query1 Dim sql1 As String = "select companyname,contactname " & _ "from customers where " & _ "companyname like 'A%'" 'query2 Dim sql2 As String = "select firstname," & _ "lastname from employees" 'combine queries Dim sql As String = sql1 + sql2 The only other change is that you loop through result sets. You nest the loop that retrieves rows inside one that loops through result sets: Do While rdr.Read() ' Print one row at a time Console.WriteLine("{0} : {1}", rdr(0), rdr(1)) End While Console.WriteLine("".PadLeft(60, "=".ToString)) Loop While rdr.NextResult() We have you choose only two character-string columns per query to simplify things. Extending this to handle result tables with different numbers of columns and column data types is straightforward.
Creating Code 128 Code Set B In Java
Using Barcode generation for Java Control to generate, create Code 128 Code Set B image in Java applications.
www.OnBarcode.com
Creating Data Matrix 2d Barcode In None
Using Barcode generation for Software Control to generate, create Data Matrix 2d barcode image in Software applications.
www.OnBarcode.com
CHAPTER 12 s USING DATA READERS
GS1 - 12 Decoder In Java
Using Barcode decoder for Java Control to read, scan read, scan image in Java applications.
www.OnBarcode.com
Generating Barcode In Objective-C
Using Barcode maker for iPhone Control to generate, create Barcode image in iPhone applications.
www.OnBarcode.com
Summary
PDF-417 2d Barcode Creator In Java
Using Barcode encoder for Android Control to generate, create PDF-417 2d barcode image in Android applications.
www.OnBarcode.com
Scanning Code-128 In Visual Studio .NET
Using Barcode recognizer for VS .NET Control to read, scan read, scan image in VS .NET applications.
www.OnBarcode.com
In this chapter, you used data readers to perform a variety of common tasks, from simply looping through single result sets to handling multiple result sets. You learned how to retrieve values for columns by column name and index and learned about methods available for handling values of different data types. You also learned how to get information about result sets and get schema information. In the next chapter, we ll cover a really interesting aspect of ADO.NET: handling database data while disconnected from the database.
CHAPTER
Using Datasets and Data Adapters
n 12, you saw how to use data readers to access database data in a connected, forward-only, read-only fashion. Often, this is all you want to do, and a data reader suits your purposes perfectly. In this chapter, you ll look at a new object for accessing data, the dataset. Unlike data readers, which are objects of data provider specific classes that implement the System.Data. IDataReader interface, datasets are objects of the class System.Data.DataSet, a distinct ADO.NET component used by all data providers. Datasets are completely independent of and can be used either connected to or disconnected from data sources. Their fundamental purpose is to provide a relational view of data stored in an in-memory cache.
s Note In yet another somewhat confusing bit of terminology, the class is named DataSet, but the generic term is spelled dataset (when one expects data set). Why Microsoft does this is unclear, especially since data set is the more common usage outside ADO.NET. Nonetheless, we ll follow the .NET convention and call Dataset objects datasets.
So, if a dataset doesn t have to be connected to a database, how do you populate it with data and save its data back to the database This is where data adapters come in. Think of data adapters as bridges between datasets and data sources. Without a data adapter, a dataset can t access any kind of data source. The data adapter takes care of all connection details for the dataset, populates it with data, and updates the data source. In this chapter, we ll cover the following: Understanding the object model Working with datasets and data adapters Propagating changes to a data source Concurrency Using datasets and XML
Copyright © OnBarcode.com . All rights reserved.