DataReader not Reading

Results 1 to 2 of 2

Thread: DataReader not Reading

  1. #1
    Join Date
    Dec 1969

    Default DataReader not Reading

    Why won&#039;t this dataReader read?<BR><BR>Dim objCon2 As New SqlConnection()<BR>objCon2.ConnectionString = "a standard connection string"<BR>objCon2.Open()<BR><BR>Dim objCommand As SqlCommand<BR>objCommand = New SqlCommand(strSQL, objCon2)<BR>Dim objReader As SqlDataReader<BR>objReader = objCommand.ExecuteReader()<BR><BR>Label1.Text = objReader("email")<BR><BR>strSQL is a select command which I&#039;ve checked (using SQL Query analyzer) does return data. I know the connection string is valid (and I presume if it wasn&#039;t that it&#039;d fail on, which it doesn&#039;t).<BR><BR>So why oh why do I get this error on the last line (and yes, there is an "email" field in the contents of the reader)<BR><BR>System.InvalidOperationException: Invalid attempt to read when no data is present.<BR><BR><BR>

  2. #2
    Join Date
    Dec 1969

    Default RE: DataReader not Reading

    You did not call objReader.Read()

Posting Permissions

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