473,394 Members | 1,841 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,394 software developers and data experts.

DataReader and JOIN query

This is the result of a JOINed query:

question answer

1 a1
1 a2
1 a3
1 a4
2 a1
2 a2
2 a3
2 a4

How would I use a DataReader to output this data without repeating each
question 4 times?

Do I weed out the repeated question in C# with a while loop?
Or is there a way to do this in the SQL statement?

Thank you for your time and help!

Sep 19 '06 #1
6 2483
Give an example of what you would like to see in the result record set.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
<de*******@yahoo.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
This is the result of a JOINed query:

question answer

1 a1
1 a2
1 a3
1 a4
2 a1
2 a2
2 a3
2 a4

How would I use a DataReader to output this data without repeating each
question 4 times?

Do I weed out the repeated question in C# with a while loop?
Or is there a way to do this in the SQL statement?

Thank you for your time and help!

Sep 19 '06 #2
Look at my example code (downloadable) at
http://sholliday.spaces.live.com/ 5/24/2006

Where I populate the Customers, and their (child) Orders, without repeating.


<de*******@yahoo.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
This is the result of a JOINed query:

question answer

1 a1
1 a2
1 a3
1 a4
2 a1
2 a2
2 a3
2 a4

How would I use a DataReader to output this data without repeating each
question 4 times?

Do I weed out the repeated question in C# with a while loop?
Or is there a way to do this in the SQL statement?

Thank you for your time and help!

Sep 19 '06 #3
I simply want to output 4 answers for every question without repeating
the question.
(with a datareader if possible)


Eliyahu Goldin wrote:
Give an example of what you would like to see in the result record set.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
<de*******@yahoo.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
This is the result of a JOINed query:

question answer

1 a1
1 a2
1 a3
1 a4
2 a1
2 a2
2 a3
2 a4

How would I use a DataReader to output this data without repeating each
question 4 times?

Do I weed out the repeated question in C# with a while loop?
Or is there a way to do this in the SQL statement?

Thank you for your time and help!
Sep 20 '06 #4
Like this?

1 a1
a2
a3
a4
2 a1
a2
a3
a4
--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
<de*******@yahoo.comwrote in message
news:11**********************@d34g2000cwd.googlegr oups.com...
>I simply want to output 4 answers for every question without repeating
the question.
(with a datareader if possible)


Eliyahu Goldin wrote:
>Give an example of what you would like to see in the result record set.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
<de*******@yahoo.comwrote in message
news:11**********************@b28g2000cwb.googleg roups.com...
This is the result of a JOINed query:

question answer

1 a1
1 a2
1 a3
1 a4
2 a1
2 a2
2 a3
2 a4

How would I use a DataReader to output this data without repeating each
question 4 times?

Do I weed out the repeated question in C# with a while loop?
Or is there a way to do this in the SQL statement?

Thank you for your time and help!

Sep 20 '06 #5
Exactly! But I'm having trouble writing the SQL code for this. Also,
this kind of model wouldn't work well with DataReader, since it read
one row at a time.

Would a DataSet be better here? (easier, perhaps?)
Eliyahu Goldin wrote:
Like this?

1 a1
a2
a3
a4
2 a1
a2
a3
a4
--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
<de*******@yahoo.comwrote in message
news:11**********************@d34g2000cwd.googlegr oups.com...
I simply want to output 4 answers for every question without repeating
the question.
(with a datareader if possible)


Eliyahu Goldin wrote:
Give an example of what you would like to see in the result record set.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
<de*******@yahoo.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
This is the result of a JOINed query:

question answer

1 a1
1 a2
1 a3
1 a4
2 a1
2 a2
2 a3
2 a4

How would I use a DataReader to output this data without repeating each
question 4 times?

Do I weed out the repeated question in C# with a while loop?
Or is there a way to do this in the SQL statement?

Thank you for your time and help!
Sep 20 '06 #6
No, you can't make a simple sql query for that. You could write a stored
procedure, but it is much easier just to do it in the code with a while
loop, as you say. A good place for this is PreRender event for the control
you use for rendering the data (GridView, repeater, etc). In this event the
control is already fully built and you can loop through the Items
collection.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
<de*******@yahoo.comwrote in message
news:11**********************@i3g2000cwc.googlegro ups.com...
Exactly! But I'm having trouble writing the SQL code for this. Also,
this kind of model wouldn't work well with DataReader, since it read
one row at a time.

Would a DataSet be better here? (easier, perhaps?)
Eliyahu Goldin wrote:
>Like this?

1 a1
a2
a3
a4
2 a1
a2
a3
a4
--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
<de*******@yahoo.comwrote in message
news:11**********************@d34g2000cwd.googleg roups.com...
>I simply want to output 4 answers for every question without repeating
the question.
(with a datareader if possible)


Eliyahu Goldin wrote:
Give an example of what you would like to see in the result record
set.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
<de*******@yahoo.comwrote in message
news:11**********************@b28g2000cwb.googleg roups.com...
This is the result of a JOINed query:

question answer

1 a1
1 a2
1 a3
1 a4
2 a1
2 a2
2 a3
2 a4

How would I use a DataReader to output this data without repeating
each
question 4 times?

Do I weed out the repeated question in C# with a while loop?
Or is there a way to do this in the SQL statement?

Thank you for your time and help!


Sep 20 '06 #7

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

Similar topics

6
by: Grant | last post by:
I am connecting to an access database using a datareader in C#. I get results when I run a certain query from Access but when I run it from Code it does not retrieve any results. I have put a stop...
5
by: Rob Wire | last post by:
For the code below, how could I add an item in the drop down lists for both company and location to be an "All" selection that would send to the stored proc. spRptAttachments a value of "%" so...
4
by: Maziar Aflatoun | last post by:
Hi everyone, I am working on the 'Delete' section of my program. What I need to do is query my database and for every ID that it finds I want to remove a file+ID.jpg from my file folder and...
3
by: Beren | last post by:
Hello, I have an sproc to query a couple of tables, that have the same fieldnames, for example DateCreated. ------------------------------------- Select a.* , b.* From tablea a Join table b...
2
by: DaveS | last post by:
Hi! I am trying to create a DataReader in .Net 2003, retrieving data from an Access backend db. In the code below, when I put a breakpoint within the While...Read() loop, the datareader returns...
1
by: Ivan Weiss | last post by:
Hey all, I have the following code to populate a ListView control from my Access database. The listview is displaying a list of saved projects that the user will be able to open, edit, or delete...
0
by: JC Voon | last post by:
Hi: The following query SELECT Inv.*, Cust.CompanyName AS Cust_Name FROM Inv JOIN Customers ON Customers.CustomerID=Inv.Cust_No When execute the DataReader.GetSchemaTable method, it will...
5
by: robecflo | last post by:
Hi Forum, i have a problem, hope somebody can give me ideas. I'm developing with windows forms and vb.net, and oracle as a database. At this moment i have a table called amortizaciones, this table...
10
by: jimmy | last post by:
Hi again, sorry for posting two questions so close together but im working on a school project which is due in soon and running into some difficulties implementing the database parts. I have the...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.