我有这个分配功能,管理员可以将警察ID分配给选定的memberreportID。首先,管理员将选择案例,选择位置并选择此案例所需的人员数量。例如,如果管理员选择了2名官员,则会显示2个下拉列表,所有绑定列表都列出了可用的policeID。
protected void ddllocation_SelectedIndexChanged(object sender, EventArgs e)
{
using (var connAdd = new SqlConnection("Data Source = localhost; Initial Catalog = MajorProject; Integrated Security= SSPI"))
{
connAdd.Open();
var sql = "Select policeid from PoliceAccount where status ='available' and handle ='offcase' and postedto='" + ddllocation.SelectedValue + "'";
using (var cmdAdd = new SqlDataAdapter(sql, connAdd))
{
DataSet ds2 = new DataSet();
cmdAdd.Fill(ds2);
ddlpid1.Items.Clear();
ddlpid1.DataSource = ds2;
ddlpid1.DataTextField = "policeid";
ddlpid1.DataValueField = "policeid";
ddlpid1.DataBind();
ddlpid1.Items.Insert(0, new ListItem("Police ID", ""));
ddlpid1.SelectedIndex = 0;
ddlpid2.Items.Clear();
ddlpid2.DataSource = ds2;
ddlpid2.DataTextField = "policeid";
ddlpid2.DataValueField = "policeid";
ddlpid2.DataBind();
ddlpid2.Items.Insert(0, new ListItem("Police ID", ""));
ddlpid2.SelectedIndex = 0;
}
}
第一个SQL命令是我如何将它们插入到我的数据库中所选memberreportID的assignto列中。我正在插入两个我已分配到同一列的警察ID,assignto。
protected void btnAssign_Click1(object sender, EventArgs e)
{
using (var connAdd = new SqlConnection("Data Source = localhost; Initial Catalog = MajorProject; Integrated Security= SSPI"))
{
String assign = ddlpid1.SelectedValue + ", " + ddlpid2.SelectedValue + ";
connAdd.Open();
var sql = "Update MemberReport Set assignto ='" + assign + "' where memberreportID='" + lbmemberreportid.Text + "'";
using (var cmdAdd = new SqlCommand(sql, connAdd))
{
cmdAdd.ExecuteNonQuery();
}
sql = "Update PoliceAccount Set handle ='" + assign + "' where policeid ='" + ddlpid1.SelectedValue + "' OR '" + ddlpid2.SelectedValue + "'";
using (var cmdAdd = new SqlCommand(sql, connAdd))
{
cmdAdd.ExecuteNonQuery();
}
connAdd.Close();
}
}
但是我也试图通过包含第二个sql命令将这个policeID输入到名为policeaccount的表中。这个policeaccount有一个名为handle
的列,用于显示他正在处理的memberreportID。我试图让每个policeID的帐户使用OR函数将选定的memberreportID接收到其句柄列中。我很确定sql语法有一个OR函数。但是当我试图插入时我得到了这个错误
An expression of non-boolean type specified in a context where a condition is expected, near ''.
答案 0 :(得分:1)
应该如下
sql = "Update PoliceAccount Set handle ='" + assign + "' where policeid ='" + ddlpid1.SelectedValue + "' OR policeid = '" + ddlpid2.SelectedValue + "'";
语法是
UPDATE tblName Set col1 ='value'
WHERE col2 ='value2'
OR col2 ='value3'