Click here to Skip to main content
15,881,380 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
private void Form1_Load(object sender, EventArgs e)
        {

            OleDbConnection con = new OleDbConnection(constr);
            OleDbCommand cmd = new OleDbCommand();

            cmd.Connection = con;

            cmd.CommandText = "select  property_name,propertytype_id from tb_property  ";
            cmd.CommandType = CommandType.Text;
            OleDbDataAdapter da = new OleDbDataAdapter();
            da.SelectCommand = cmd;
            DataSet ds = new DataSet();
            da.Fill(ds);
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {

                for (int j = 0; j < 2; j++)
                {
                    dataGridView1.Rows.Add(new DataGridViewRow());
                    dataGridView1.Rows[i].Cells[j].Value = ds.Tables[0].Rows[i][j].ToString();
                }
            }
            con.Close();
}
here in this code i am fetching two values from database and displaying them in datagridview...
now the problem is that the second field that i am fetching from database that is propertytype_id ...in my database there is another table named tb_property_type and in that table there is a property name and a value corresponding to every id...now in this datagridview i want to display value corresponding to the the propertytype_id in the other table...can anyone halp me out??
Posted
Updated 20-Jan-14 19:53pm
v2
Comments
Programm3r 21-Jan-14 1:55am    
Hi, why can't you just make use of entity framework? http://msdn.microsoft.com/en-us/data/ef.aspx

1 solution

Change your query to this, you will be able to get the value. and you can modify in the loop.

SQL
"select  a.property_name,a.propertytype_id , b.propertytype_value  from tb_property a  inner join tb_property_type b
 on a.propertytype_id = b.propertytype_id"
 
Share this answer
 
Comments
Member 10512838 21-Jan-14 2:03am    
its not showing the values...it is still showing the id @karthik
Karthik_Mahalingam 21-Jan-14 2:05am    
"select a.property_name, b.propertytype_value from tb_property a inner join tb_property_type b
on a.propertytype_id = b.propertytype_id"
Karthik_Mahalingam 21-Jan-14 2:05am    
try this query...
Member 10512838 21-Jan-14 2:06am    
but its the same query you have posted above
Karthik_Mahalingam 21-Jan-14 2:10am    
u replace with this
see clearly...
select a.property_name,a.propertytype_id , b.propertytype_value from
to
select a.property_name, b.propertytype_value from

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