在我的项目中,有一个组合框“状态”,其中三个值处于活动状态,处于活动状态和工作状态。根据要求,所选值应表示为整数,因此我编写了代码以便存储所选值的索引。现在的问题是,当我在更新状态时尝试从组合框中选择值时,它应该在列表视图中显示为值。如果我选择 0 它应该显示为活动,1 为非活动,2 为工作。到目前为止我用来获取值的代码如下,请帮助我将值获取到该整数。
private void btnUpdateSupport_Click(object sender, EventArgs e)
{
SqlConnection con = Helper.getconnection();
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
string SupportName = txtSupportName.Text;
string SupportDesignation = txtSupportDesignation.Text;
//string SupportStatus = txtSupportStatus.Text;
string SupportStatus = cbSupportStatus.SelectedItem.ToString();
//string SupportStatus = SqlCommand();
int i = 0;
string s = "Active";
// string result = int.TryParse(s, out i);
if (cbSupportStatus.SelectedItem != null)
{
int x = int.Parse(cbSupportStatus.SelectedItem.ToString());
}
else
{ //Value is null }
cmd.CommandText = "Update Status1 set Designation='" + SupportDesignation + "', Status='" + SupportStatus + "' where Name= '" + SupportName + "' ";
MessageBox.Show(cmd.CommandText);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}