0

Hi.

I guess this is a very simple question, but really cant fint the answer that suits my needs!

What I have is 2 tables in a MySQL database:

Families
- FamilyId
- City
- Phone

Members
- FamilyId
- Birtdate

The family id is of course the primary key, that binds members to a family.
So what I want is to get the right family row, and all member rows that belongs to this family like this:

string Query="SELECT * FROM `Families`, `Members` WHERE `Families`.`FamilyId`='132' AND `Members`.`FamilyId`='123';";

But how do I iterate over the result, so that I can create the corresponding family object, and the corresponding Member objects that I have in my C# application?

MysqlConnection.Open();
          MySqlCommand MysqlCommand=new MySqlCommand(Query,MysqlConnection);
          MysqlReader=MysqlCommand.ExecuteReader();

          while (MysqlReader.Read()) {
            //what should I do here?
          }
2
Contributors
1
Reply
3
Views
6 Years
Discussion Span
Last Post by smantscheff
1

I don't know about C# but I noticed a design flaw in your query. Do not use more than one literal value to link the two tables:

SELECT * FROM `Families`, `Members` WHERE `Families`.`FamilyId`='132' AND `Members`.`FamilyId`=`Families`.`FamilyId`;

In your sample code you use two different FamilyIds which is exactly the kind of error which might occur with your query.

Votes + Comments
good omment about literal value but here need is to tell about atleast n-1 combination condition
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.