Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have two table named cpu and sell and i want to get data in gridview
table cpu has name,image1
table sell has cost,brand
C#
SqlCommand cmd = new SqlCommand("SELECT name,image1,Min(cost),MAX(cost) FROM sell,cpu WHERE cpu.name=sell.brand", con);
        SqlDataAdapter da = new SqlDataAdapter(cmd);     
         DataTable dt = new DataTable();
                da.Fill(dt);
                GridView1.DataSource = dt;
                GridView1.DataBind();

but this error appear when run
Ambiguous column name 'name'.
Posted
Updated 17-Nov-13 8:12am
v3
Comments
abbaspirmoradi 17-Nov-13 14:16pm    
are you have column "name" also in your sell table?
m-e-h-d-h-i 17-Nov-13 14:40pm    
No
m-e-h-d-h-i 17-Nov-13 14:43pm    
I have tried your solution but another error apears...
Column 'cpu.name' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause
abbaspirmoradi 17-Nov-13 14:51pm    
ok ,well this is your next problem. check this:"SELECT cpu.name,image1,Min(cost),MAX(cost) FROM sell,cpu WHERE cpu.name=sell.brand group by(cpu.name)"

1 solution

Try this:

C#
SqlCommand cmd = new SqlCommand("SELECT cpu.name,image1,Min(cost),MAX(cost) FROM sell,cpu WHERE cpu.name=sell.brand group by(cpu.name)", con);
 
Share this answer
 
v2

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