Get 1st record in ADO.Net

S

sam

I not familiar at ASP.Net 1.1 because I were ASP 3.0 programmer.

I just wanna get 1st record in data but I don't know to code at ASP.Net 1.1


ASP 3.0
-------
Set rsFILE = Server.CreateObject("ADODB.Recordset")
rsFILEstatm = "SELECT * FROM F4111 ORDER BY ILUKID DESC"
rsFILE.Open rsFILEstatm, ConnAS400

rsFILE.movefirst

lastnum = CDbl(rsFILE("ILUKID"))

rsFILE.close
Set rsFILE = Nothing
Set rsFILEstatm = Nothing


Asp.Net 1.1
-----------
Dim constrDBL As String = "server='SQLSVR'; Database='JDE_ERP'"
Dim sqlconDBL As System.Data.SqlClient.SqlConnection = New
System.Data.SqlClient.SqlConnection(constrDBL)
Dim sqlcmdDBL As System.Data.SqlClient.SqlCommand = New
System.Data.SqlClient.SqlCommand("SELECT * FROM F4111 ORDER BY ILUKID DESC",
sqlconDBL)

Try
sqlconDBL.Open

Dim dbrDBL As System.Data.SqlClient.SqlDataReader =
sqlcmdDBL.ExecuteReader(System.Data.CommandBehavior.CloseConnection)

Do While dbrDateFr.Read

' How to write get first record then exit

Loop

sqlcmdDBL = Nothing
dbrDBL = Nothing
Finally
sqlconDBL.Close
sqlconDBL.Dispose()

End Try

constrDBL = Nothing
sqlconDBL = Nothing

Please guide me.

Many thanks.
 
A

A.J

sam said:
I not familiar at ASP.Net 1.1 because I were ASP 3.0 programmer.

I just wanna get 1st record in data but I don't know to code at ASP.Net 1.1


ASP 3.0
-------
Set rsFILE = Server.CreateObject("ADODB.Recordset")
rsFILEstatm = "SELECT * FROM F4111 ORDER BY ILUKID DESC"
rsFILE.Open rsFILEstatm, ConnAS400

rsFILE.movefirst

lastnum = CDbl(rsFILE("ILUKID"))

rsFILE.close
Set rsFILE = Nothing
Set rsFILEstatm = Nothing


Asp.Net 1.1
'make the following changes:
Dim constrDBL As String = "server=SQLSVR; Database=JDE_ERP"
Dim sqlconDBL As System.Data.SqlClient.SqlConnection = New
System.Data.SqlClient.SqlConnection(constrDBL)
Dim sqlcmdDBL As System.Data.SqlClient.SqlCommand = New
System.Data.SqlClient.SqlCommand("SELECT * FROM F4111 ORDER BY ILUKID DESC",
sqlconDBL)

Try
sqlconDBL.Open

Dim dbrDBL As System.Data.SqlClient.SqlDataReader =
sqlcmdDBL.ExecuteReader(System.Data.CommandBehavior.CloseConnection)

Do While dbrDateFr.Read

' How to write get first record then exit
TextBox1.Text = dbrDBL("NAME")
'if the database is having a column name as "name"; then the
'textbox "textbox" will contain the first record of that column
 
C

Cor Ligthert

sam,

If you want to do the same as a recordset, than you have to look at a
datatable.

Now you are using a sequential datareader, which gives you the records one
by one, however does not store those in a table as it is with the recordset
and the datatable.

I hope this helps,

Cor
 
G

Guest

Hi Sam,

If you want to get the 1st record and only the 1st, I suggest rewriting your
TSQL statement to
"SELECT TOP 1 * FROM F4111 ORDER BY ILUKID DESC".

It is fast and you are not fetching records you won't use.

Thanks!!!
 

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

Similar Threads


Top