Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
example:


combobox0(product id) = ?
combobox1(product type) = Glass
combobox2(product subtype) = Commodity Glass
combobox3(product name)= Clear Float Glass
combobox4(product dimension) = 12 x 12 in

can you improve the code:

C#
string query = "select * from RawMat WHERE ProductName = '" +  cboproductname.SelectedItem.ToString() + "'";
Posted
Updated 1-Jul-12 2:07am
v2
Comments
Zoltán Zörgő 1-Jul-12 8:24am    
It really depends on the data structure of your database - and your user requirements. If you are designing the database right now, you should consider tagging products with class=value pairs. This way filtering the product list is only a matter of matching tags. The only improvement at this point is using parameters instead of query string concatenation. You can also make cascading master-detail datasets and let the framework do the rest...

1 solution

Yes.

1) Don't use "SELECT * FROM..." - specifiy your fields instead.
2) Do not concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead.
 
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