0

我有这个分配功能,管理员可以将警察 ID 分配给选定的 memberreportID。首先,管理员将选择案件,选择地点并选择案件所需的人员数量。例如,如果管理员选择了 2 名警官,那么它将显示 2 个下拉列表全部绑定以列出可用的警察 ID。

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 列中。我将我分配的两个policeID 插入到同一列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 命令将此policyID 输入到名为policyaccount 的表中。这个policeaccount有一个名为的列handle,假设显示他正在处理的memberreportID。我试图让每个policeID 的帐户通过使用OR 函数将选定的memberreportID 接收到他们的句柄列中。我很确定sql语法有一个OR函数。但是当我尝试插入时,我得到了这个错误

An expression of non-boolean type specified in a context where a condition is expected, near ''.
4

1 回答 1

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'
于 2013-08-02T09:10:41.907 回答