Click here to Skip to main content
15,879,017 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Good day Ma'am and Sir. I want to select cause from table 1 and select address from table2 where unique_id = @uniqueid. Both tables have primary key called unique_id. and get the their value using DataReader.

What I have tried:

using(MySqlConnection con = new MySqlConnection(connString))
           {
               consp.Open();
               string clientid = "009";
               MySqlDataReader reader;
               MySqlCommand com = new MySqlCommand("SELECT FROM ",con);
               com.Parameters.AddWithValue("@uniqueid,"clientid);
               reader = com.ExecuteReader();
               while(reader.HasRows && reader.Read())
               {
                 string cause;
                 string address;
                 cause = reader.GetString(reader.GetOrdinal());
                 address = reader.GetString(reader.GetOrdinal());
               }

           }
Posted
Updated 26-Jun-17 15:59pm

1 solution

Why not use a JOIN statement?
Note: I had not tested this query, intended to post it on comment but not working.
SQL
MySqlCommand com = new MySqlCommand("SELECT clause, address FROM table1 JOIN table2 ON table1.unique_id = table2.unique_id WHERE table1.unique_id = @uniqueid",con);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900