|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Newbie Question: How Does One Access an Individual Field in a Record?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 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(); } -- Show quoteHide quoteHope this helps, Mark Fitzpatrick Former Microsoft FrontPage MVP 199?-2006 "Rick" <rich***@ccpspeople.com> wrote in message news:Tyzkh.9791$ZT3.8305@newssvr19.news.prodigy.com... >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 >
How to change the font style and size on the entire Aspx page programatically
Ajax Triggers for DropDownList don't fire Embeding html controls in Server Control Pass parameter from pages aspx Regular Expression Validator question Generating the *.aspx.designer.vb Files Merry Christmas from Windward launch page and redirect with LinkButton How to access templated controls in user control? How to collect the data from input created by document.write() in ASP.NET? |
|||||||||||||||||||||||