PC Review


Reply
Thread Tools Rate Thread

cannot get the SqlDataReader object field value

 
 
Matt
Guest
Posts: n/a
 
      29th Oct 2003
I just want to get the value of field UserName and Password in SqlDataReader
object dr. But it yeields run-time error "Invalid attempt to read when no
data is present" on line dr("UserName") and dr("Password")

any ideas??

Dim sql As String = "select * from [Admin] where UserName = '" &
TextBox1.Text & "'" _
& "AND Password = '" & TextBox2.Text & "'" & ";"
Dim cmd As New SqlCommand(sql, cn)
cmd.Connection.Open()
Dim dr As SqlDataReader
dr = cmd.ExecuteReader()
Response.Write("User Name = " & dr("UserName"))
Response.Write("Password = " & dr("Password"))




 
Reply With Quote
 
 
 
 
IbrahimMalluf
Guest
Posts: n/a
 
      29th Oct 2003
add theses lines to code:

Do While dr.Read
Response.Write("User Name = " & dr("UserName"))
Response.Write("Password = " & dr("Password"))
Loop



"Matt" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> I just want to get the value of field UserName and Password in

SqlDataReader
> object dr. But it yeields run-time error "Invalid attempt to read when no
> data is present" on line dr("UserName") and dr("Password")
>
> any ideas??
>
> Dim sql As String = "select * from [Admin] where UserName = '" &
> TextBox1.Text & "'" _
> & "AND Password = '" & TextBox2.Text & "'" & ";"
> Dim cmd As New SqlCommand(sql, cn)
> cmd.Connection.Open()
> Dim dr As SqlDataReader
> dr = cmd.ExecuteReader()
> Response.Write("User Name = " & dr("UserName"))
> Response.Write("Password = " & dr("Password"))
>
>
>
>



 
Reply With Quote
 
William \(Bill\) Vaughn
Guest
Posts: n/a
 
      29th Oct 2003
if dr.HasRows ' in Version 1.1 of the Framework
Do While dr.Read
Response.Write("User Name = " & dr("UserName"))
Response.Write("Password = " & dr("Password"))
Loop
Else
Response.Write ("No user info on file...")
End if


--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
MVP, hRD
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________

"IbrahimMalluf" <(E-Mail Removed)> wrote in message
news:%23p6B0$(E-Mail Removed)...
> add theses lines to code:
>
> >

>
> "Matt" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
> > I just want to get the value of field UserName and Password in

> SqlDataReader
> > object dr. But it yeields run-time error "Invalid attempt to read when

no
> > data is present" on line dr("UserName") and dr("Password")
> >
> > any ideas??
> >
> > Dim sql As String = "select * from [Admin] where UserName = '" &
> > TextBox1.Text & "'" _
> > & "AND Password = '" & TextBox2.Text & "'" & ";"
> > Dim cmd As New SqlCommand(sql, cn)
> > cmd.Connection.Open()
> > Dim dr As SqlDataReader
> > dr = cmd.ExecuteReader()
> > Response.Write("User Name = " & dr("UserName"))
> > Response.Write("Password = " & dr("Password"))
> >
> >
> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can I retrieve a SqlDataReader from a SqlConnection object? Valerie Hough Microsoft ADO .NET 1 3rd Feb 2007 01:18 PM
SQLDatareader field length banana boy Microsoft ADO .NET 1 1st Nov 2005 07:38 PM
Using reflection to give back a sqldatareader object Hans ter Wal via DotNetMonster.com Microsoft VB .NET 0 26th Apr 2005 09:51 AM
problem referencing field in sqldatareader andrew Microsoft ADO .NET 6 7th Jan 2004 05:11 PM
cannot get the SqlDataReader object field value Matt Microsoft ADO .NET 4 29th Oct 2003 09:52 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:46 AM.