Can someone help me why Im getting NullReferenceException? I have a Filter function and want to Clear the items of a CheckBox before gettin new Items.
if(comboboxSearch.Items != null)
{
comboboxSearch.Items.Clear();
}
LoadColumns();
I get Error in (if(comboboxSearch.Items != null)
And an Error in LoadColumns:
try
{
connection = new MySqlConnection(conf.connection_string);
if(this.OpenConnection() == true)
{
using (var schemaCommand = new MySqlCommand(columns_sql, connection))
{
using (var reader = schemaCommand.ExecuteReader(CommandBehavior.SchemaOnly))
{
schema = reader.GetSchemaTable();
}
}
foreach (DataRow col in schema.Rows)
{
comboboxSearch.Items.Add(UppercaseFirst(col.Field<String>("ColumnName")));
}
}
this.CloseConnection();
}
catch(MySqlException ex)
{
MessageBox.Show(ex.Message);
}
At comboboxSearch.Items.Add(UppercaseFirst(col.Field<String>("ColumnName")));
In another Code the foreach works without if null check too. I dont Understand why I get this Error now because i check if it's null..