sud*_*ara 0 c# sql sql-server conditional-statements
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 " +
time_start_int + " <= " + 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;
Run Code Online (Sandbox Code Playgroud)
我想获取sql表time_start_int之间的列值time_end_int
我收到了错误
'<'附近的语法不正确.
您无法start <= column <= end在SQL查询中编写.
你需要这样做:
"...and start_cd >= " + time_start_int + " and " + start_cd + " <= " + time_end_int
Run Code Online (Sandbox Code Playgroud)
但请不要连接你的字符串,这使你容易受到SQL注入.使用SQL参数.