On 23 Feb 2005, ".Net Sports" <ba********@cox.net> postulated in
news:11**********************@f14g2000cwb.googlegr oups.com:
Subject: DataList, Repeater, or Data Grid?
From: ".Net Sports" <ba********@cox.net>
Newsgroups: microsoft.public.dotnet.framework.aspnet
I am resurrecting an old script from a previous programmer, and
want to migrate it over to asp.net from classic asp. Tho there are other
peripheral parts of the script (that really have no bearing on the
core, in which I will explain), the main core is the concern. I
have a daily feed from a horseracing prognosticator that gets put into an
sql database on a daily basis for roughly 15 popular racetracks. A user
(who will need a usern/password) will come to a page that lists the
tracks available for that day, click on a link for a track, and
will come to the page and script in question. From the database will be
data from 3 different tables: tblRace (the # of race for that day, the
racedate the trackID, other auxiliary info like track length, horse
ages for a race, ), tblTrack (trackname, trackID) , tblHorseentry
(the horses name, the gate position, speed rating, other aux info) .
tblHorseentry has a raceid, relational key with tblRace, and a
trackid is in relation with tblhorseentry and tbltrack. Below is the SQL
statement:
'''sql stmt'''
<% sqlstr ="SELECT
tblhorseentry.horsename,tblhorseentry.gatepos,tblh orseentry.bestbet
,tblhorseentry.topplay,tblhorseentry.rating,tblhor seentry.speedpr,tbl
race.raceid,tblrace.racedate,tblrace.raceno,tblrac e.racelength,tblrac
e.raceturf,tblrace.racedescription,tblrace.horseag e,tbltrack.tracknam
e FROM tblrace INNER JOIN tblhorseentry ON tblhorseentry.raceid =
tblrace.raceid INNER JOIN tbltrack ON tblrace.trackid =
tbltrack.trackid WHERE trackname = '" &
request.querystring("trackname") & "' and racedate = '" &
request.querystring("racedate") & "' AND raceno = 1 AND rating =
1;" %>
The problem here is at the end, where along with the querystrings
bringing over the trackname and racedate, this sqlstring will bring
up just the horsesname and auxiliary info for just the first race, and
if he is the favored horse (rating) for this particular race by
information compiled by the horseracing handicapper. I need to find
a way to grab all the racenumbers (raceno) and ratings in an array
and somehow loop thru the array until the end of the recordset (asp) or
dataset (asp.net).
With those obstacle in mind, how can I start to set this up in
asp.net. Will a DataList that just templates everything out, or a Repeater
control be best, or will even a DataGrid control encompass
everything I need to accomplish?
Thanks for any input
E.M.
.Net Sports
E.M.
All of the data list controls that you mention are webcontrols, that
is, they are user interface controls for displaying the data.
The classes that you shold explore are the ones designed for the
backend data tier, within the Data namespace and are referred to in
general as ADO.NET.
First readup on ADO.net in general. Note that Dot Net is designed for
n-tier design practices, so you must understand the conceptual
paradigm.
Thenm get to know the connection and command objects. These are
SIMILAR to ADO, but not exact. The key to returning data from your
sql statement is through the Command object. Since you are dealing
with lists of records, you'll next need to understand the objects
that model a view in your application.
In ASP, we used an ADORecordset. No such thing in ADO.NET. What we
now use are either a SQLDataReader or a DataAdapter.
Both are similar, but a DataAdapter is a high-end data repository
designed to cache multiple tables in your application. It is actually
a mini database, a kind of front-end processor for SQL Server. While
your description seems to imply that you would benefit from using a
DataAdapter, this may not be entirely true, as a this object is quite
complicated and takes some experience to use efficiently.
A SQLDataReader is most similar to an ASP style disconnected
ADORecordset, so if your model app uses these, then porting to ASP
might be simpler, at least in the first pass, using these. They are
usually sufficient to read data and forward to any of the datalist
type webcontrols you have listed above.
Look at the ASP.NET examples supplied with the SDK and also available
online at:
http://samples.gotdotnet.com/quickstart/aspplus/
Make special note of the examples titled: Server-side Data Access and
Data Binding to Server Controls.
good luck
-- ipgrunt