lyric0n
Technical User
- Dec 28, 2005
- 74
Hello,
I am working with a different tables and I need to make various queries in my application. I am able to establish a connection to my SQL 2000 server and use the reader to read the first table, but when I try to use another reader (and the same connection) to read another table, I get an error saying there is already a DataReader associated with this command.
Here is my code...
'Establish connection
Dim strConn As String = "Data Source=server;Initial Catalog=Sample;Integrated Security=SSPI;"
Dim objSqlConn As New System.Data.SqlClient.SqlConnection(strConn)
objSqlConn.Open()
'Open the first set
Dim strQuery As String = "SELECT * FROM dbo.Temp"
Dim objSqlCommand As New SqlCommand(strQuery, objSqlConn)
Dim myReader As SqlDataReader
myReader = objSqlCommand.ExecuteReader()
myReader.Read() 'This works okay.
'Open/close the second set of data
Dim objReader As SqlDataReader
strQuery = "SELECT * From dbo.Bleh"
Dim objSQLTemp As New SqlCommand(strQuery, objSqlConn)
objReader = objSQLTemp.ExecuteReader() ' This is where I get the error
objReader.Read()
objReader.Close()
'Close the first set
myReader.Close()
objSqlConn.Close()
Do I really need to establish two connection to retrieve two sets of data? Or is there something I am missing?
Thanks for the help,
Chris
I am working with a different tables and I need to make various queries in my application. I am able to establish a connection to my SQL 2000 server and use the reader to read the first table, but when I try to use another reader (and the same connection) to read another table, I get an error saying there is already a DataReader associated with this command.
Here is my code...
'Establish connection
Dim strConn As String = "Data Source=server;Initial Catalog=Sample;Integrated Security=SSPI;"
Dim objSqlConn As New System.Data.SqlClient.SqlConnection(strConn)
objSqlConn.Open()
'Open the first set
Dim strQuery As String = "SELECT * FROM dbo.Temp"
Dim objSqlCommand As New SqlCommand(strQuery, objSqlConn)
Dim myReader As SqlDataReader
myReader = objSqlCommand.ExecuteReader()
myReader.Read() 'This works okay.
'Open/close the second set of data
Dim objReader As SqlDataReader
strQuery = "SELECT * From dbo.Bleh"
Dim objSQLTemp As New SqlCommand(strQuery, objSqlConn)
objReader = objSQLTemp.ExecuteReader() ' This is where I get the error
objReader.Read()
objReader.Close()
'Close the first set
myReader.Close()
objSqlConn.Close()
Do I really need to establish two connection to retrieve two sets of data? Or is there something I am missing?
Thanks for the help,
Chris