简体   繁体   中英

Can't Check weather selected Combo Box Value is null

How to check selected combobox value is null? I am filling comboboxes with these functions:

string sql = "select employee from db_company";
SqlDataReader dr = Db.loadData(sql);
if(cbox.Items.Count == 0)
{
    while (dr.Read())
    {
        cbox.Items.Add(dr[0].ToString());
    }
}

In another class, loadData function is:

public SqlDataReader loadData(string sql, params object[] parameters)
{
    SqlCommand command = new SqlCommand(sql, Db);
    for (int i = 0; i < parameters.Length;)
    {
        command.Parameters.AddWithValue(parameters[i++] as string, parameters[i++]);
    }
    SqlDataReader dr = command.ExecuteReader();
    return dr;
}  

and I'm trying to check with this function:

public bool nullCheck(params object[] parameters)
{
    bool check = true;
    for(int i = 0; i < parameters.Length; i++)
    {
        if (parameters[i] == null)
            check = false;
    }
    return check;
}

And when I pass combobox or textBox values as parameters to nullCheck(), the debug says for comboBox,

System.Windows.Forms.ComboBox, Items.Count 14

I'm trying to figure out how can I handle this, I tried some ways, for example showing the value of combobox, however messagebox shows null.

我不确定请尝试 if (parameters[i].ToLower() == "null")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM