【发布时间】:2020-02-13 10:10:28
【问题描述】:
在我的表格中,我已经从多个下拉列表中插入了值,现在我想在我的 c# 代码的 where 子句中传递这些值,请帮助
SqlCommand command = new SqlCommand("select distinct comp_type from master_office_complaint
where comp_id='" + reader["marked_officer"]+ "'", conn);
这里marked_officer 列包含多个值。
【问题讨论】:
-
您需要一个
WHERE comp_id IN (...)子句。现在,我们的目标是保护该查询免受 SQL 注入。 -
这能回答你的问题吗? Pass Array Parameter in SqlCommand
-
我尝试过使用 in 子句,但我得到零响应
-
使用参数,为了避免 sql 注入,您的查询应该是: select distinct comp_type from master_office_complaint where comp_id in (select value from string_split(@marked_officer, ','))
-
@MarcGuillot 我收到此错误 -System.Data.SqlClient.SqlException: '必须声明标量变量“@marked_officer”。'
标签: javascript c# .net sql-server