Execute Reader Example : Database Reader « Database ADO.net « VB.Net

Home
VB.Net
1.2D
2.Application
3.Class
4.Data Structure
5.Data Types
6.Database ADO.net
7.Date Time
8.Development
9.Event
10.File Directory
11.Generics
12.GUI
13.Internationalization I18N
14.Language Basics
15.LINQ
16.Network Remote
17.Reflection
18.Security
19.Thread
20.Windows Presentation Foundation
21.Windows System
22.XML
23.XML LINQ
VB.Net Tutorial
VB.Net by API
VB.Net » Database ADO.net » Database ReaderScreenshots 
Execute Reader Example
  


Imports System
Imports System.Data
Imports System.Data.SqlClient

    Public Class MainClass

        Public Shared Sub ExecuteReaderExample(ByVal con As IDbConnection)
            Dim com As IDbCommand = con.CreateCommand
            com.CommandType = CommandType.Text
            com.CommandText = "SET ROWCOUNT 10;SELECT Production.Product.Name, Production.Product.ListPrice FROM Production.Product ORDER BY Production.Product.ListPrice DESC;SET ROWCOUNT 0;"
            Using reader As IDataReader = com.ExecuteReader
                While reader.Read
                    Console.WriteLine("  {0} = {1}", reader("Name"), reader("ListPrice"))
                End While
            End Using
        End Sub
        Public Shared Sub Main()
            Using con As New SqlConnection
                con.ConnectionString = "Data Source=.\sqlexpress;Database=AdventureWorks;Integrated Security=SSPI;"
                con.Open()

                ExecuteReaderExample(con)
                con.Close()
            End Using
        End Sub
    End Class

   
    
  
Related examples in the same category
1.Use SqlDataReader to read a single row of dataUse SqlDataReader to read a single row of data
2.Select top 5 Records in data tableSelect top 5 Records in data table
3.Execute Scalar Example
4.Execute the command and retrieve and XmlReader to access the results
w___w___w___.__j_a__va___2__s.__c__o__m___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.