Accessing records w/o datagrids, etc...

M

MRW

Hello!

I'm an ASPer moving on to .NET. I've been searching the web for my
answer, but I've been, suprisingly, unable to find a good answer. I was
hoping you can help.

Back in ASP, if I wanted to check the db for a record (let's say an
Employee Login), all I would have to do is get the recordset and write:

If objRS.EOF Then
Response.write "No Employee Exists"
Else
Response.write "Welcome " & objRS("FirstName")
End If

And that was nice and pretty. I'm trying to do the same thing with
..NET, and my code looks like:

Dim objAdapter As New OleDbDataAdapter(strSQL, objConnection)
Dim objDataSet As New DataSet()
objAdapter.Fill(objDataSet, "tblEmployees")

If objDataSet.Tables("tblEmployees").Rows.Count = 0 Then
Message.Text = "There is no user with that ID"
Else
Message.Text = "Welcome " +
objDataSet.Tables("tblEmployees").Rows(0)("FirstName")
End If

Does it have to be this LONG. Especially accessing records in this
form:

objDataSet.Tables("tblEmployees").Rows(0)("FirstName")

While in ASP it was simply:
objRS("FirstName")

??

I can't seem to find any info on this area for whatever reason. Any
help on simplifying the process is GREATLY appreciated!
 
K

Ken Cox - Microsoft MVP

Hi,

Welcome to the world of .NET!

True, ASP.NET can be a little longer. Then again, you haven't shown us all
you need to do to get the recordset.

Anyway, to shorten it up and make it fasater, you'll want to try
ExecuteScalar. It gives you a quick hit for checking one field:

Dim myCommand As New SqlCommand(myScalarQuery, myConnection)
myCommand.Connection.Open()
myCommand.ExecuteScalar()
myConnection.Close()

http://msdn.microsoft.com/library/d...qlclientsqlcommandclassexecutescalartopic.asp

Ken
Microsoft MVP [ASP.NET]
 
P

Patrick.O.Ige

MRW it simply depends what you want to do.
You will get to know its much faster alter on
Patrick
 
M

MRW

I simply would like to play with and manipulate my data as I see fit.
I want to be able to access any record in the dataset and either
display it, or use it as part of a hyperlink, etc...

I want an ASP.NET equivilent to objRS("LastName"), so I don't have to
spend ten minutes writing out one line of code :)
 

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,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top