473,663 Members | 2,743 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Please, need help to finish a query. Thank You.

Hello,

I have three tables: Polls (PollId, Question), Options (OptionID,
Answer) and Votes (VoteID, OptionID)

I then created two Wrapper Classes:

PostPaper with the following properties:
public Poll Poll { get; set; }
public List<OptionPape rOptions { get; set; }
public string OptionsCSV { get; set; }

OptionPaper with the following properties:
public Option Option { get; set; }
public int Votes { get; set; }

I need, given an PollId, to get fill a PostPaper with all its options
and for each option count the votes:

pollViewData.Po llPaper = (from p in database.Polls
join o in database.Option s on p.PollID
equals o.PollID
join v in database.Votes on o.OptionID
equals v.OptionID
where p.PollID == id
group o by p into pog
select new PollPaper {
Poll =
pog.Key,
Options = new List<OptionPape r{
Option = ??????
Votes = ?????
}.ToList(),
OptionsCSV = string.Join(", ",
pog.Select(o =o.Answer).ToAr ray())
}).SingleOrDefa ult();

I am having problems in creating the Option and Count the votes of
each OptionPaper in List Options.

Could someone, please, help me out?

Thanks,
Miguel

Sep 30 '08 #1
3 1118
On Sep 30, 1:33*am, shapper <mdmo...@gmail. comwrote:
Hello,

I have three tables: Polls (PollId, Question), Options (OptionID,
Answer) and Votes (VoteID, OptionID)

I then created two Wrapper Classes:

* *PostPaper with the following properties:
* * * public Poll Poll { get; set; }
* * * public List<OptionPape rOptions { get; set; }
* * * public string OptionsCSV { get; set; }

* *OptionPaper with the following properties:
* * * public Option Option { get; set; }
* * * public int Votes { get; set; }

I need, given an PollId, to get fill a PostPaper with all its options
and for each option count the votes:

* * * pollViewData.Po llPaper = (from p in database.Polls
* * * * * * * * * * * * * * * * join o indatabase.Opti ons on p.PollID
equals o.PollID
* * * * * * * * * * * * * * * * join v indatabase.Vote s on o.OptionID
equals v.OptionID
* * * * * * * * * * * * * * * * where p.PollID == id
* * * * * * * * * * * * * * * * group o by p into pog
* * * * * * * * * * * * * * * * select new PollPaper {
* * * * * * * * * * * * * * * * * Poll =
pog.Key,
* * * * * * * * * * * * * * * * * Options = new List<OptionPape r{
* * * * * * * * * * * * * * * * * * Option = ??????
* * * * * * * * * * * * * * * * * * Votes = ?????
* * * * * * * * * * * * * * * * * }.ToList(),
* * * * * * * * * * * * * * * * * OptionsCSV = string.Join(", ",
pog.Select(o =o.Answer).ToAr ray())
* * * * * * * * * * * * * * * * }).SingleOrDefa ult();

I am having problems in creating the Option and Count the votes of
each OptionPaper in List Options.

Could someone, please, help me out?

Thanks,
Miguel
Please, anyone? I have been trying to make this work but until now I
wasn't able.

Thanks,
Miguel
Sep 30 '08 #2
I've come up with something like this:

PostPaper pp = new PostPaper();
pp.Poll = (from p in Polls where p.PollID == pollID select p).First();
var opts = (from o in Options where o.PollID == pollID select o);

OptionPaper op;
foreach (Option o in Options)
{
op = new OptionPaper();
op.Option = o;
op.Votes = (from v in Votes where v.OptionID == o.OptionID select
v).Count();
pp.Options.Add( op);
}
"shapper" <md*****@gmail. comwrote in message
news:89******** *************** ***********@l42 g2000hsc.google groups.com...
On Sep 30, 1:33 am, shapper <mdmo...@gmail. comwrote:
Hello,

I have three tables: Polls (PollId, Question), Options (OptionID,
Answer) and Votes (VoteID, OptionID)

I then created two Wrapper Classes:

PostPaper with the following properties:
public Poll Poll { get; set; }
public List<OptionPape rOptions { get; set; }
public string OptionsCSV { get; set; }

OptionPaper with the following properties:
public Option Option { get; set; }
public int Votes { get; set; }

I need, given an PollId, to get fill a PostPaper with all its options
and for each option count the votes:

pollViewData.Po llPaper = (from p in database.Polls
join o in database.Option s on p.PollID
equals o.PollID
join v in database.Votes on o.OptionID
equals v.OptionID
where p.PollID == id
group o by p into pog
select new PollPaper {
Poll =
pog.Key,
Options = new List<OptionPape r{
Option = ??????
Votes = ?????
}.ToList(),
OptionsCSV = string.Join(", ",
pog.Select(o =o.Answer).ToAr ray())
}).SingleOrDefa ult();

I am having problems in creating the Option and Count the votes of
each OptionPaper in List Options.

Could someone, please, help me out?

Thanks,
Miguel
Please, anyone? I have been trying to make this work but until now I
wasn't able.

Thanks,
Miguel

Oct 1 '08 #3
On Oct 1, 3:02*am, "Family Tree Mike"
<FamilyTreeM... @ThisOldHouse.c omwrote:
I've come up with something like this:

* *PostPaper pp = new PostPaper();
* *pp.Poll = (from p in Polls where p.PollID == pollID select p).First();
* *var opts = (from o in Options where o.PollID == pollID select o);

* *OptionPaper op;
* *foreach (Option o in Options)
* *{
* * op = new OptionPaper();
* * op.Option = o;
* * op.Votes = (from v in Votes where v.OptionID == o.OptionID select
v).Count();
* * pp.Options.Add( op);
* *}

"shapper" <mdmo...@gmail. comwrote in message

news:89******** *************** ***********@l42 g2000hsc.google groups.com...
On Sep 30, 1:33 am, shapper <mdmo...@gmail. comwrote:
Hello,
I have three tables: Polls (PollId, Question), Options (OptionID,
Answer) and Votes (VoteID, OptionID)
I then created two Wrapper Classes:
PostPaper with the following properties:
public Poll Poll { get; set; }
public List<OptionPape rOptions { get; set; }
public string OptionsCSV { get; set; }
OptionPaper with the following properties:
public Option Option { get; set; }
public int Votes { get; set; }
I need, given an PollId, to get fill a PostPaper with all its options
and for each option count the votes:
pollViewData.Po llPaper = (from p in database.Polls
join o in database.Option s on p.PollID
equals o.PollID
join v in database.Votes on o.OptionID
equals v.OptionID
where p.PollID == id
group o by p into pog
select new PollPaper {
Poll =
pog.Key,
Options = new List<OptionPape r{
Option = ??????
Votes = ?????
}.ToList(),
OptionsCSV = string.Join(", ",
pog.Select(o =o.Answer).ToAr ray())
}).SingleOrDefa ult();
I am having problems in creating the Option and Count the votes of
each OptionPaper in List Options.
Could someone, please, help me out?
Thanks,
Miguel

Please, anyone? I have been trying to make this work but until now I
wasn't able.

Thanks,
Miguel
I am using the following:

PollPaper paper = (from p in database.Polls
where p.PollID == id
select new PollPaper {
Poll = p,
OptionsCSV = string.Join("," ,
p.Options.Selec t(op =op.Answer).ToA rray()),
Options = (from o in p.Options
select new OptionPaper() {
Option = o,
Votes = o.Votes.Count
}).ToList()
}).SingleOrDefa ult();

In think it is ok ... but could someone give me some feedback?

Thanks,
Miguel
Oct 1 '08 #4

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

Similar topics

9
3531
by: DD | last post by:
Hello, Could anyone please help me?? Is there somebody who could explain me how to make a connection to a access database with a python cgi script. I would like to use common sql commands in my python scripts as I can with MySQLdb. But I cannot even connect to the access database (see below). Could anyone explain it to me as simple as possible please. I'm using Windows XP, ActivePython 2.3.2 build 230 and Microsoft access(XP?)
4
2653
by: Orion | last post by:
Hi, This is kind of last minute, I have a day and a half left to figure this out. I'm working on a project using ms-sqlserver. We are creating a ticket sales system, as part of the system, I need to be able to do a search for specific tickets withing price ranges, different locations within the theaters, etc. etc. My problem is in the search one of the criteria is to search for a group of seats together. For example let's say...
8
19589
by: Andrew McNab | last post by:
Hi folks, I have a problem with an MS Access SQL query which is being used in an Access Report, and am wondering if anyone can help. Basically, my query (shown below) gets some records from a couple of tables in my database using INNER JOINS and the WHERE clause to specify the required constraints. However, I also want to read two fields from a *single* record from a table called 'Locations' and then apply one of these field's values...
9
2408
by: hope | last post by:
Hi Access 97 I'm lost on this code please can you help ================================= Below is some simple code that will concatenate a single field's value from multiple records into a single string separated by a user defined character. There is no error trapping (by design), USE AT YOUR OWN RISK.
14
3097
by: alwayshouston | last post by:
Hi All! I am working on this very small database and I am confused in the designing a simple form. I only have three tables in the database. First Table: tblExpense Columns: ExpenseID ; ExpenseType Data: 1 ; FOOD 2 ; AIRLINE 3 ; FARE
1
1076
by: Miguel Dias Moura | last post by:
Hello, i am creating an ASP.net / VB web site with Dreamweaver MX 2004. I have a form and a "Insert Record Behavior" to insert the form values in the database. Dreamweaver puts this code in the end of the form: ... <input type="hidden" name="MM_insert" value="myForm"> (1)
4
1759
by: Miguel Dias Moura | last post by:
Hi, I just uploaded a web site and i am getting an error. I have a script which sends form values to an email using AspNetEmail. The script was working when i was calling the script like this: <asp:Button ID="Finish" runat="server" OnClick="sendEmail"> However, in this new web site version, when the button is pressed, to scripts are supose to run. So i replaced the button code with this:
1
9623
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej and I was wondering if anyone here would be able to give me some tips for young players such as myself, for learning the language. Is this the best Newsgroup for support with JAVA?
5
3361
by: Y2J | last post by:
I am working through this book on C++ programming, the author is speaking of using linked lists. He gave and example which I found confusing to say the least. So I rewrote the example in a way that I could better understand the concept, he was trying to convey to me. I ran my own example and it crashed and burn "what a surprise!" : (. I ran the authors example out of the book and quess what, it crashed also, : 0. I ran them both on my...
0
8858
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8771
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8548
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8634
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7371
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6186
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
2763
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2000
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1757
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.