【发布时间】:2014-02-16 08:04:11
【问题描述】:
String start_cd;
String end_cd;
int time_start_int;
int time_end_int;
opencon();
SqlCommand res = new SqlCommand("SELECT ID,Available,Type," + start_cd + "," + end_cd + " FROM " + going + " WHERE " + start_cd + "!=0 or " + end_cd + "!=0 and " + start_cd + " >= " + time_start_int + " and " + start_cd + " <= " + time_end_int + "", con);
SqlDataAdapter sda_res = new SqlDataAdapter(res);
DataTable dt_res = new DataTable();
sda_res.Fill(dt_res);
listBox1.DataSource=dt_res;
listBox1.DisplayMember="ID";
listBox2.DataSource = dt_res;
listBox2.DisplayMember = start_cd;
我没有收到任何错误 但列表框显示未过滤的值(我想在 time_end_int 之间获取值 time_start_int )
【问题讨论】:
-
人们已经在您之前的问题中告诉过您,您将字符串连接起来创建查询是过时且有风险的。
-
即使您坚持编写有 SQL 注入问题的代码,请花时间编辑您的示例,这样就不需要滚动(滚动浏览您的示例以尝试猜测错误是不必要的困难) .
标签: c# sql sql-server