Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

CreateDataReader_Sql - Create a SqlClient Data Reader

Total Hit ( 2641)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


Click here to copy the following block
' return a DataReader over a SqlConnection
'
' CONNSTRING is the connection string
' SQL is the SQL Select statement to be executed
'
' the connection will be automatically closed when the DataReader is disposed
' any exception is returned to the caller

Function CreateDataReader_Sql(ByVal connString As String, _
  ByVal sql As String) As System.Data.SqlClient.SqlDataReader
  ' open the connection
  Dim cn As New System.Data.SqlClient.SqlConnection(connString)
  cn.Open()
  ' prepare the SQL SELECT command
  Dim cmd As New System.Data.SqlClient.SqlCommand(sql, cn)
  ' create a DataReader - note the CloseConnection argument
  ' which causes the Connection to be closed when the DataReader is disposed
  Dim dr As System.Data.SqlClient.SqlDataReader = cmd.ExecuteReader _
    (CommandBehavior.CloseConnection)
  ' dispose the Command object and return the result
  cmd.Dispose()
  Return dr
End Function


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.