get record field value in ASP.NET

M

Matt

In ASP 3.0, rs("field_name") is able to get the value of field_name in a
recordset.

In ASP.NET using VB.NET, I think SqlDataReader is the substitute of
recordset? I don't quit understand how to use it.

Here's my code attempts, but it yields run-time error "Invalid attempt to
read when no data is present"on dr(i).ToString

Dim cn As New SqlConnection(cs)
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()
For i = 0 To dr.FieldCount - 1
strLine = strLine & dr.GetName(i).ToString & Chr(9) & dr(i).ToString
Next


Please advise!
Thanks!
 
G

Guest

(...)

While oDR.Read ' oDR is of type SqlDataReader
strValue = oDR("field_name")
End While

(...)

Ben
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,772
Messages
2,569,591
Members
45,103
Latest member
VinaykumarnNevatia
Top