Click here to Skip to main content
16,017,650 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
have a dropdownlist getting data from the categories table in the database. and filling the gridview on the bases of the catagories..

ESK_Categories Table

CateogoryID,Category name.

ESK_Products Table

ProductID,CategoryID(fk),ProductName,UnitCost



sql query is
C#
string query = "SELECT ESK_Products.ProductID, ESKProducts.ProductName,ESK_Products.UnitCost ,ESK_Cateogries.CategoryName FROM ESK_Products LEFT JOIN ESK_Categories ON ESK_Products.ProductsID=ESK_Categories.CategoryID Where CategoryName='" + DropDownList1.Text + "'";  

This is some problem in query. pls anyone help me to correct it..
Posted
Updated 4-Sep-11 1:56am
v2

1 solution

Whet's the error / problem you're facing?

At least one problem you may encounter is if the text contains ' -characters, your concatenation won't result to a valid SQL statement. Use parameters instead: http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlparameter.aspx[^].

Another thing is that if you're trying to get products per categories and product should always have a category, try switching the tables in the LEFT JOIN.

If there's some other error, post the error message in whole. If the error is logical, try describing what is the expected result etc.
 
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