C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !






Using the SqlDataReader Object


Posted Date: 13 Jan 2008    Resource Type: Code Snippets    Category: ADO.NET

Posted By: @@@ Hyderabadi Biryani @@@       Member Level: Diamond
Rating:     Points: 10



The SqlDataReader object provides what is sometimes called a firehose cursor from a SQL Server Express statement that returns data. The firehose cursor is a set of records that is optimized for quick retrieval. The data returned by the SqlDataReader can only be read once, from the start of the results to the end, and it’s always read-only. The first step to using the SqlDataReader object is to open it. You can’t instantiate a SqlDataReader object directly using the new keyword. Instead, you must use the ExecuteReader method of a SqlCommand object.




Imports System.Data.SqlClient

Module Module1

Sub Main()

Dim conStr As String = _
"Initial Catalog=AdventureWorks;" & _
"Data Source=localhost;Integrated Security=SSPI;"

Dim con As SqlConnection = New SqlConnection(conStr)

' Create the command object.
Dim cmd As SqlCommand = New SqlCommand("SELECT * FROM Person.Contact")
cmd.Connection = con

' Open the connection and execute the command.
con.Open()
Dim dr As SqlClient.SqlDataReader = cmd.ExecuteReader()
Console.WriteLine("HAS ROWS?: " & dr.HasRows)
dr.Close()
con.Close()

Console.WriteLine()
Console.WriteLine("PRESS ANY KEY TO EXIT")
Console.ReadLine()

End Sub

End Module








Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Inserting Data With Different Server Controls
Previous Resource: DataTableReader in ADO.NET 2.0
Return to Discussion Resource Index
Post New Resource
Category: ADO.NET


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

Help Desk

Contact Us    Privacy Policy    Terms Of Use