我将如何创建一个可以充当where
子句的字符串? 目前,我做这样说:根据下拉列表选择创建SQL查询
string strquery = "select * from tbl_DR_data ";
string strq2 = "where [Year 1]='" + DropDownList1.SelectedItem.Text + "'and Product='" + DropDownList2.SelectedItem.Text +
"'and Media='" + DropDownList3.SelectedItem.Text + "'and Publication='" + DropDownList4.SelectedItem.Text + "'and Genre='" + DropDownList5.SelectedItem.Text +
"'and Month='" + DropDownList6.SelectedItem.Value + "'and Section='" + DropDownList7.SelectedItem.Text + "'";
string str3 = strquery + strq2;
但问题是,所有的下拉列表中必须有内它们的值。 我希望能够根据什么下拉有一个值在init中创建一个where语句。因此,例如DDL1和DDL4具有值,但不包括所有其他下拉列表。
我该怎么去做这个?
一定要使用参数化查询。您的代码已准备好进行sql注入。 – venerik
+1 @venerik。另外,为皮特的缘故使用ORM! –