simple question

K

Kelly

I am from classic asp and learning asp.net. In the past, once I have a
recordset retrieved, I can use it wheneve and wherever I want. For example,
I know my recordset contains something like rs("firstname"), I can do
<%=rs("firstname")%> anywhere in the web page. How do we achieve it in
asp.net?

Sorry for the simple question, but please help.
 
S

Scott M.

Well, that question is actually a bit more complicated now, since in ASP
..NET and ADO .NET, we don't have recordsets any more.

If you are looking for a connected, read-only, and forward-only way of
iterating over your results, you can use a DataReader once you've executed
your command and then loop through it so you can see your returned records
one by one.

If you need to persist your data a bit longer than this, or if you need to
be able to back up through the records, ADO .NET provides us with a DataSet
(which is like an in memory relational database). A DataSet is disconnected
from the source of the data so, you can access your data at any time after
populating your DataSet by accessing the table(s) of data that it contains
and then the Row(s) that you are interested in and finally the Item
(column/field) of that row.

Since the DataSet is a disconnected copy of the resultset, you can access
its data at any time throughout your code after you populate it.

-Scott
 
P

Peter Bromberg [C# MVP]

Kelly,
A good place to start for all this "Stuff" is the QUICKSTARTS tutorials
which installs with either Visual Studio or the .NET Framework SDK, or you
can use the online version at the ASP.NET Site:
http://quickstarts.asp.net/QuickStartv20/default.aspx

I don't want to sound like a broken MP3, but really - I've been doing .NET
since the first beta in 2000, and I still use the QUICKSTARTS today.
-- Peter
http://www.eggheadcafe.com
http://petesbloggerama.blogspot.com
http://www.blogmetafinder.com
 
P

Phil H

I am from classic asp and learning asp.net. In the past, once I have a
recordset retrieved, I can use it wheneve and wherever I want. For example,
I know my recordset contains something like rs("firstname"), I can do
<%=rs("firstname")%> anywhere in the web page. How do we achieve it in
asp.net?

Sorry for the simple question, but please help.

I am inclined to agree with Peter Bromberg. As a piece of advice to
all former ASP programmers. Don't assume that ASP.NET is and extention
of ASP it isn't! It's a completely different platform.

The real underlying innovation is in Framework which draws together
experience from a variety of technologies and source languages. It's
great but it does require a lot of fresh learning from the developers
point of view.
 
J

John Timney \(MVP\)

Assuming firstname was the first item from the first row in the first
datatable in your dataset.
<%= mydataset.tables(0).rows(0).item(0)%>
or
<%= mydataset.tables(0).rows(1).item("firstname")%> will for example return
an item called firstname from the 2nd row in the 1st datatable in your
dataset

Binding in asp.net isn't the same as calling details from a recordset as
recordsets only had one result set in, where a dataset in asp.net can have
many tabels and results.

So, you would be better off executing code (in page_load for example) to
populate a string, int etc. and then binding to that in each of your
controls either as code in the method label1.text =
mydataset.tables(0).rows(0).item(0), or as <% =firstname %> inline. Inline
code is not the recommended approach, even if the other way sometimes takes
more code.

Regards

John Timney (MVP)
http://www.johntimney.com
http://www.johntimney.com/blog
 
K

Kelly

Thanks, Scott. But what I want to achieve is to build my own html table and
have the data populated into the cells. I know there are data bound controls
to use, such as gridview, repeater, etc. But they cannot be freely modified
as I want, it seems to me. For example, if I want to populate the stuff from
2 data sources into 1 html table, gridview, repeater controls won't work for
me. I am looking for .net equivalent to <%=recordset("firstname")%>. Is
that such a thing available?
 
K

Kelly

This is exactly what I want. Thanks.

John Timney (MVP) said:
Assuming firstname was the first item from the first row in the first
datatable in your dataset.
<%= mydataset.tables(0).rows(0).item(0)%>
or
<%= mydataset.tables(0).rows(1).item("firstname")%> will for example return
an item called firstname from the 2nd row in the 1st datatable in your
dataset

Binding in asp.net isn't the same as calling details from a recordset as
recordsets only had one result set in, where a dataset in asp.net can have
many tabels and results.

So, you would be better off executing code (in page_load for example) to
populate a string, int etc. and then binding to that in each of your
controls either as code in the method label1.text =
mydataset.tables(0).rows(0).item(0), or as <% =firstname %> inline. Inline
code is not the recommended approach, even if the other way sometimes takes
more code.

Regards

John Timney (MVP)
http://www.johntimney.com
http://www.johntimney.com/blog
 
S

Scott M.

Again Kelly, I'll refer you to my first post.

If you want to be able to access the data anywhere in your page response,
you'll need to store it...and that means a Dataset. Then, you can dig into
that DataSet and extract what you want, when you want.

-Scott
 

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

Top