Need help using a datareader

Results 1 to 3 of 3

Thread: Need help using a datareader

  1. #1
    Join Date
    Dec 1969

    Default Need help using a datareader

    The following code errors off at myEmailReader = myEmailCommand.ExecuteReader()<BR>stating There is already an open DataReader associated with this Connection which must be closed first. Can I not dim another datareader and try to use it. What must i do to access a second data reader<BR><BR><BR> Dim conn As New SqlConnection("server=myServer;initial catalog=myDB;user id=12345;password=aaa;")<BR> conn.Open()<BR> Dim myCommand As New SqlCommand("select * from profile where empid in (919999,123456)", conn)<BR> Dim mySecReader As SqlDataReader<BR> mySecReader = myCommand.ExecuteReader(CommandBehavior.CloseConne ction)<BR><BR><BR> While mySecReader.Read()<BR> Dim str<BR> Dim strSec As String<BR> Dim strEmail As String = ""<BR> Dim strSecEmail As String<BR><BR> str = mySecReader("sect")<BR> Response.Write(str) &#039;test<BR><BR> strSec = str<BR><BR> Dim SQLstmt As String<BR> SQLstmt = "select,p.empid "<BR> SQLstmt = SQLstmt & "from dpss_emp_email d,PROFILE p"<BR> SQLstmt = SQLstmt & " where d.employee_number = p.empid "<BR> SQLstmt = SQLstmt & " and p.sect = "<BR> SQLstmt = SQLstmt & "&#039;" & strSec & "&#039;"<BR><BR> Dim myEmailCommand As New SqlCommand(SQLstmt, conn)<BR> Dim myEmailReader As SqlDataReader<BR> myEmailReader = myEmailCommand.ExecuteReader()<BR><BR> While myEmailReader.Read<BR><BR> strSecEmail = myEmailReader("email")<BR> strEmail = strEmail & strSecEmail & ","<BR><BR><BR> End While<BR> Response.Write(str)<BR> Response.Write(strEmail)<BR><BR> End While<BR>

  2. #2
    Join Date
    Dec 1969

    Default after the While loop, put


  3. #3
    Join Date
    Dec 1969

    Default RE: Need help using a datareader

    The answer to your question is that, no you cannot assign more than one sqldatareader to a connection at a time. You could try using a dataset model instead which would then free up your connection

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts