Datareader Problem

Results 1 to 2 of 2

Thread: Datareader Problem

  1. #1
    Join Date
    Dec 1969

    Default Datareader Problem

    Hi,<BR>I am using a sqldatareader. Here is my code. If records are found its displaying properly. But when no records are found its throwing Invalid attempt to read when no data is present. <BR>instead of displaying the text.<BR><BR>dr = sqlcom.ExecuteReader()<BR> dr.Read()<BR><BR><BR> If dr.GetValue(0) = 0 Then<BR> Label1.Text = "Invalid Login"<BR> &#039;Response.Redirect("login.aspx?res=invalid")< BR> Else<BR> Session("UNAME") = Trim(txtuserid.Text)<BR> Session("ROLE") = dr.GetValue(0)<BR> Session("AUTH") = 1<BR> Response.Redirect("index.aspx")<BR> End If<BR><BR>What is the problem? The else part is working abs fine. but when no records are found I need to display the text in the label.

  2. #2

    Default RE: Datareader Problem

    You should consider using the DataAccess Application Block.<BR><BR>Returning a single value? Probably better to use ExecuteScalar.<BR>Returning a small number of rows? Probably better to use a DataSet (disconnected by nature).<BR><BR><BR>Probably need to check (dr.Read() == null)<BR>

Posting Permissions

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