473,382 Members | 1,147 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Reading Datasets

et
How do I read a dataset so that I get only one value of one field, then read
the entire database. For instance, I'm doing a database of bakery products,
want to list all cakes. General query, Select * from tblProducts where
Category = 'Cakes"
So I read the first row so tht I can get a heading, then want to list all
items. But because I've already "read" the first row, the list of all items
do not contain the first item in my datareader. How do I fix this, do I
have to do 2 queries, one to get the heading, then the second query to get
the list of products under that heading. Seems to me that's going backwards
from using recordsets.

dr.Read

Response.Write(" <tr><td colspan=3><font size=+1><b>" &
dr("Category")</td></tr>")

while dr.read

Response.Write("<tr><td>" & dr("ProductName") & "</td><td>")

end while

Nov 18 '05 #1
1 1598

"et" <ea*************@yahoo.com> wrote in message
news:%2***************@TK2MSFTNGP15.phx.gbl...
How do I read a dataset so that I get only one value of one field, then
read
the entire database. For instance, I'm doing a database of bakery
products,
want to list all cakes. General query, Select * from tblProducts where
Category = 'Cakes"
So I read the first row so tht I can get a heading, then want to list all
items. But because I've already "read" the first row, the list of all
items
do not contain the first item in my datareader. How do I fix this, do I
have to do 2 queries, one to get the heading, then the second query to get
the list of products under that heading. Seems to me that's going
backwards
from using recordsets.

dr.Read

Response.Write(" <tr><td colspan=3><font size=+1><b>" &
dr("Category")</td></tr>")

while dr.read

Response.Write("<tr><td>" & dr("ProductName") & "</td><td>")

end while


There are two answers here. First, your immediate problem is just a coding
problem.

dr.Read

Response.Write(" <tr><td colspan=3><font size=+1><b>" &
dr("Category")</td></tr>")

do
Response.Write("<tr><td>" & dr("ProductName") & "</td><td>")
loop while dr.Read()

But this, and 100 similar problems can be avoided by using a DataSet instead
of a DataReader. You have to force your program logic to conform to the
forward-only nature of the DataReader. This example is easy to work around,
but others aren't so much. Just byte the bullet and use DataSets, and then
you can sort, group, loop, compute, cache, etc to get the data when you need
it, not when you have to.

David

Nov 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Klatuu | last post by:
Whew, I've struggled my way through figuring out how to use XML to transport data..now I can imagine what having a baby is like :) But, I'm stuck now. I generate the XML (single table, no...
4
by: Alpha | last post by:
I have a small Window application and through out the different forms I create a different dataset. At the begining I used the Tools to drag and drop the SqlDataAdapter, connection and dataset...
1
by: jty202 | last post by:
If I have String containing the code of a HTML <table> with data in it, can a dataset read in the data thats contain in a HTML table? If so, can someone show me. Can this also be done with Comma...
16
by: Luqman | last post by:
Is it recommended to use datasets in ASP.Net 2.0 / VS.Net 2005 ? Best Regards, Luqman
4
by: Ronald S. Cook | last post by:
I've always used untyped datasets. In a Microsoft course, it walks through creating typed datasets and harps on the benefits. It has you drag all these things around ..wizard, wizard, wizard......
25
by: Penelope Dramas | last post by:
Hello, I'm in a front of very serious .net redesign/rewrite of an old VB6 application. I had been asked to make it .NET 2.0 and would like to ask couple of questions regarding data access as...
2
by: S.Tedeschi | last post by:
Hi all gurus. I'm trying to switch to VS 2005, from VS 2003. I've an ASP.NET 1.1 app heavily relying on StronglyTyped DataSets, with lots of FindByKey..., dataSet.Tablename, and similar methods....
0
by: S.Tedeschi | last post by:
Hi all; as posted some days ago, I'm converting an on-line app; I used to heavily rely on strongly-typed DataSets directly dropped onto pages, and so viewed by code(-behind) as well. In the next...
9
by: gardnern | last post by:
We have X number of data sets, of Y length each. For example... Small, Medium, Large and Red, Green, Blue, Yellow We need to generate a list of all possibilities Small Red
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.