473,322 Members | 1,614 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

get record field value in ASP.NET

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!
Nov 17 '05 #1
1 1654
(...)

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

(...)

Ben
-----Original Message-----
In ASP 3.0, rs("field_name") is able to get the value of field_name in arecordset.

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

Here's my code attempts, but it yields run-time error "Invalid attempt toread 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).ToStringNext
Please advise!
Thanks!
.

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Steve | last post by:
I have a form with about 25 fields. In the BeforeUpdate event of the form, I have code that sets the default value of each field to its current value. For a new record, I can put the focus in any...
1
by: Scott269 | last post by:
So I've got an old MS Works database I imported into Access. I needed a primary key so I created a record number field that was just the record number I manually inserted when I entered it in the...
2
by: Mark Reed | last post by:
Hi All, I have created a multi-user application at work which is working perfectly apart from a small problem which I believe to more a of a user issue (maybe some will set me straight on that...
1
by: roveagh1 | last post by:
Hi I've been using the 2 year old link below to repeat values from previous record field into current corresponding field. It's worked fine for text but the last piece of advice was to use the same...
1
by: Sunray | last post by:
I have a form called the sales form and i have 2 sets of listboxes So what happens is. i add items form the bottom set of list boxes which are bound to a data base to the top set of list boxes which...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.