0
我有一個查詢將在此情況下返回值和庫存類別。如果用戶輸入某個框號,則表單應該禁用,如果它是表單將啓用的其他內容。問題是我使用ExecuteScalar並需要將該值與字符串「AP」進行比較。我對C#很陌生,無法弄清楚如何做到這一點。這裏是我的代碼到目前爲止:將對象與if語句中的變量進行比較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();
}
請標記爲答案,如果這解決了您的問題... – Madushan 2012-08-08 08:08:39