vb.net qr code sample Getting Data About Data in Visual Basic .NET

Encoding Data Matrix in Visual Basic .NET Getting Data About Data

Getting Data About Data
Paint ECC200 In VB.NET
Using Barcode creator for Visual Studio .NET Control to generate, create DataMatrix image in VS .NET applications.
www.OnBarcode.com
Scanning Data Matrix 2d Barcode In Visual Basic .NET
Using Barcode reader for Visual Studio .NET Control to read, scan read, scan image in .NET framework applications.
www.OnBarcode.com
So far, all you ve done is retrieve data from a data source. Once you have a populated data reader in your hands, you can do a lot more. Here are a number of useful methods for retrieving schema information or retrieving information directly related to a result set. Table 7-4 describes some of the metadata methods and properties of a data reader.
Creating Matrix Barcode In Visual Basic .NET
Using Barcode generator for .NET Control to generate, create Matrix 2D Barcode image in VS .NET applications.
www.OnBarcode.com
GS1 128 Creator In Visual Basic .NET
Using Barcode printer for .NET Control to generate, create USS-128 image in .NET framework applications.
www.OnBarcode.com
Table 7-4. Data Reader Metadata Properties and Methods Method or Property Name
Make QR-Code In Visual Basic .NET
Using Barcode maker for .NET Control to generate, create QR Code 2d barcode image in .NET applications.
www.OnBarcode.com
Universal Product Code Version A Creator In Visual Basic .NET
Using Barcode encoder for .NET Control to generate, create GTIN - 12 image in Visual Studio .NET applications.
www.OnBarcode.com
Depth FieldCount GetDataTypeName GetFieldType
DataMatrix Generator In Visual Basic .NET
Using Barcode maker for VS .NET Control to generate, create Data Matrix 2d barcode image in .NET applications.
www.OnBarcode.com
Printing OneCode In Visual Basic .NET
Using Barcode encoder for Visual Studio .NET Control to generate, create USPS OneCode Solution Barcode image in .NET applications.
www.OnBarcode.com
Description
Encoding DataMatrix In VS .NET
Using Barcode maker for Reporting Service Control to generate, create DataMatrix image in Reporting Service applications.
www.OnBarcode.com
Generating Data Matrix 2d Barcode In Java
Using Barcode generator for Android Control to generate, create ECC200 image in Android applications.
www.OnBarcode.com
A property that gets the depth of nesting for the current row A property that holds the number of columns in the current row A method that accepts an index and returns a string containing the name of the column data type A method that accepts an index and returns the .NET Framework type of the object
Painting Data Matrix In Objective-C
Using Barcode maker for iPad Control to generate, create Data Matrix ECC200 image in iPad applications.
www.OnBarcode.com
Read Barcode In Visual Studio .NET
Using Barcode reader for VS .NET Control to read, scan read, scan image in VS .NET applications.
www.OnBarcode.com
Continued
Print QR Code 2d Barcode In Visual C#.NET
Using Barcode creation for .NET Control to generate, create QR Code ISO/IEC18004 image in .NET applications.
www.OnBarcode.com
Code 39 Drawer In Objective-C
Using Barcode encoder for iPad Control to generate, create Code 3 of 9 image in iPad applications.
www.OnBarcode.com
CHAPTER 7 s INTRODUCING DATA READERS
Barcode Encoder In .NET Framework
Using Barcode encoder for .NET Control to generate, create Barcode image in VS .NET applications.
www.OnBarcode.com
Drawing Code-39 In None
Using Barcode printer for Font Control to generate, create Code 39 Extended image in Font applications.
www.OnBarcode.com
Table 7-4. Continued Method or Property Name
Paint Denso QR Bar Code In None
Using Barcode drawer for Software Control to generate, create Quick Response Code image in Software applications.
www.OnBarcode.com
Barcode Creation In Objective-C
Using Barcode encoder for iPhone Control to generate, create Barcode image in iPhone applications.
www.OnBarcode.com
GetName GetOrdinal GetSchemaTable HasRows RecordsAffected
Create Code128 In Visual Studio .NET
Using Barcode maker for Reporting Service Control to generate, create Code 128C image in Reporting Service applications.
www.OnBarcode.com
Decoding Code 39 Full ASCII In VB.NET
Using Barcode decoder for VS .NET Control to read, scan read, scan image in .NET applications.
www.OnBarcode.com
Description
A method that accepts an index and returns the name of the specified column A method that accepts a column name and returns the column index A method that returns column metadata A property that indicates if the data reader has any rows A property that gets the number of rows changed, inserted, or deleted
Try It Out: Getting Information About a Result Set with a Data Reader
Let s use some of these methods and properties. 1. Add a new Console Application project named ResultSetInfo to your 07 solution. 2. Replace the code in Module1.vb with the code in Listing 7-4.
Listing 7-4. ResultSetInfo: Module1.vb
Imports System Imports System.Data Imports System.Data.SqlClient Module Module1 Sub Main() ' Set up connection string Dim connString As String = _ "server = .\sqlexpress;" _ & "integrated security = true;" _ & "database = northwind" ' Set up query Dim sql As String = _ "select " _
CHAPTER 7 s INTRODUCING DATA READERS
& & & & & &
" contactname, " _ " contacttitle " _ "from " _ " customers " _ " where " _ " contactname like 'M%'"
' 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() ' Get column names Console.WriteLine( _ "Column Name: {0} {1}", _ rdr.GetName(0).PadRight(25), _ rdr.GetName(1) _ ) ' Get column data types Console.WriteLine( _ "Data Type: {0} {1}", _ rdr.GetDataTypeName(0).PadRight(25), _ rdr.GetDataTypeName(1) _ ) Console.WriteLine() ' Loop through result set While rdr.Read Console.WriteLine( _ " {0} {1}", _ rdr.GetString(0).PadRight(25), _ rdr.GetString(1) _
CHAPTER 7 s INTRODUCING DATA READERS
) End While ' Get number of columns Console.WriteLine() Console.WriteLine( _ "Number of columns in a row: {0}", _ rdr.FieldCount _ ) ' Get info about each column Console.WriteLine( _ "'{0}' is at index {1} and its type is: {2}", _ rdr.GetName(0), _ rdr.GetOrdinal("contactname"), _ rdr.GetFieldType(0) _ ) Console.WriteLine( _ "'{0}' is at index {1} and its type is: {2}", _ rdr.GetName(1), _ rdr.GetOrdinal("contacttitle"), _ rdr.GetFieldType(1) _ )
' Close data reader rdr.Close() Catch e As Exception ' Display error Console.WriteLine("Error: " & e.ToString) Finally ' Close connection conn.Close() End Try End Sub End Module
CHAPTER 7 s INTRODUCING DATA READERS
3. Make this the startup project, and run it with Ctrl+F5. You should see the result in Figure 7-4.
Figure 7-4. Displaying result set metadata
How It Works
The GetName method gets a column name by its index. This method returns information about the result set, so it can be called before the first call to Read():
' Get column names Console.WriteLine( _ "Column Name: {0} {1}", _ rdr.GetName(0).PadRight(25), _ rdr.GetName(1) _ )
The GetDataTypeName method returns the database data type of a column. It too can be called before the first call to Read():
' Get column data types Console.WriteLine( _ "Data Type: {0} {1}", _ rdr.GetDataTypeName(0).PadRight(25), _ rdr.GetDataTypeName(1) _ )
CHAPTER 7 s INTRODUCING DATA READERS
The FieldCount property of the data reader contains the number of columns in the result set. This is useful for looping through columns without knowing their names or other attributes:
' Get number of columns Console.WriteLine() Console.WriteLine( _ "Number of columns in a row: {0}", _ rdr.FieldCount _ )
Finally, we demonstrated how the GetOrdinal and GetFieldType methods are used. The former returns a column index based on its name; the latter returns the VB type. These are the converses of GetName() and GetDataTypeName(), respectively.
' Get info about each column Console.WriteLine( _ "'{0}' is at index {1} and its type is: {2}", _ rdr.GetName(0), _ rdr.GetOrdinal("contactname"), _ rdr.GetFieldType(0) _ )
So much for obtaining information about result sets. You ll now learn how to get information about schemas.
Copyright © OnBarcode.com . All rights reserved.