我有一个查询将在这种情况下返回一个值和库存类别。如果用户输入某个框号,则如果表单将启用其他任何内容,则表单应禁用。问题是我使用 ExecuteScalar 并且需要将该值与字符串“AP”进行比较。我对 C# 很陌生,无法弄清楚如何做到这一点。到目前为止,这是我的代码:
private void hide_apple_controls()
{
SqlCommand cmd = new SqlCommand();
Object invCat;
cmd.CommandText = "SELECT itm.inv_cat FROM " +
"t_item_master itm " +
"LEFT OUTER JOIN t_box box (NOLOCK) ON box.product_code LIKE itm.item_number " +
"where box.box_id = @box_id ";
cmd.Parameters.Add("@box_id", SqlDbType.VarChar).Value = boxBox.Text;
cmd.CommandType = CommandType.Text;
cmd.Connection = this.sqlConnection1;
this.sqlConnection1.Open();
SqlDataAdapter adpt = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
adpt.Fill(ds);
invCat = cmd.ExecuteScalar();
this.sqlConnection1.Close();
string ap = "AP";
if (invCat == ap )
{
disable_qc_form();
}
enable_qc_form();
}