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?
          }

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.

commented: good omment about literal value but here need is to tell about atleast n-1 combination condition +2
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.