Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Web Controls / December 2006

Tip: Looking for answers? Try searching our database.

Newbie Question: How Does One Access an Individual Field in a Record?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Rick - 27 Dec 2006 19:10 GMT
I can connect to a sql server database, I can query the database, and I can
display the results in a datalist, but how can I refer to an individual
field from a query?  My query is from a sql command in a datasource.

For example: SELECT CUSTOMER FROM CUSTOMERS.

How do I use asp.net to refer to customer[1], customer[2], etc.  Let's say
if I just wanted to display customer number 45 in a table:

<table>
<td>***customer[45]***</td>
</table>

How can I do that?

I'm normally a coldfusion developer, and I'm having difficulty
transitioning.

Thanks in advance,

Rick
Mark Fitzpatrick - 28 Dec 2006 15:36 GMT
It all depends upon which method you are using. If you are using a
datareader, you can't do this because a datareader provides a row by row
look a the records. It doesn't jump around, just moves to the next row. A
datareader also doesn't know how many records are being returned so it's not
possible to look for a single one.

What you want is a datatable probably. A datatable is an xml structure
created by ado.net to hold the results of your query. It has rows and column
and you can visualize it as a spreadsheet. You can use the Rows.Count
property to find the number of rows, just in case there is no row 45 for
your customers (and remember, 0 is the first row and 1 is the second, all
arrays begin with zero).

DataTable myTable = ... populate table from query
string customer = string.Empty;
if(myTable.Rows.Count >= 45)
{
    // the following gets the value in column 0 of row number 45
   customer = myTable.Rows[44][0].ToString();
}

Signature

Hope this helps,
Mark Fitzpatrick
Former Microsoft FrontPage MVP 199?-2006

>I can connect to a sql server database, I can query the database, and I can
>display the results in a datalist, but how can I refer to an individual
[quoted text clipped - 17 lines]
>
> Rick

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.