要将条件 cboDeprtdep 值添加到查询中,可以通过以下步骤完成:

  1. 获取 cboDeprtdep 值。假设 cboDeprt 是一个名为 cboDeprt 的 ComboBox 控件,可以使用 cboDeprt.SelectedValue 属性来获取选定的值。

  2. dep 值添加到查询条件中。在查询语句中的 WHERE 子句后面添加 dep = @dep,并为参数 @dep 设置值。

修改代码如下:

private void dtpkanBan_ValueChanged(object sender, EventArgs e)
{
    DateTime selectedDate = dtpKanBan.Value.Date;
    string depValue = cboDeprt.SelectedValue.ToString(); // 获取 cboDeprt 的 dep 值

    string connectionString = "Server=192.168.1.180;initial catalog=DB_2015_20211029;user id=sa;password=gdzy5tgb6yhn;Connect Timeout=5";
    using (SqlConnection connection = new SqlConnection(connectionString))
    {
        connection.Open();

        string query = "SELECT mo_no FROM mf_mo WHERE sta_dd = @selectedDate AND dep = @dep"; // 添加 dep 条件
        SqlCommand command = new SqlCommand(query, connection);
        command.Parameters.AddWithValue("@selectedDate", selectedDate);
        command.Parameters.AddWithValue("@dep", depValue); // 设置 dep 参数值

        using (SqlDataReader reader = command.ExecuteReader())
        {
            listBox1.Items.Clear();
            while (reader.Read())
            {
                string moNo = reader.GetString(0);
                listBox1.Items.Add(moNo);
            }
        }
    }
}

请确保将 cboDeprt 控件的 ValueMember 属性设置为 dep,以便正确获取 dep

private void dtpkanBan_ValueChangedobject sender EventArgs e DateTime selectedDate = dtpKanBanValue; DateTime selectedDate = dtpKanBanValueDate; 只获取日期部分 Messa

原文地址: http://www.cveoy.top/t/topic/iJYP 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录