0
Hello, I need to develop an advanced search filter. I created some comboBoxs for the keywords, but whenever I need to fetch the contents of a column that eventually has less content than another particular column, the combobox is filled with Cells in Null.
the 1st Combo I’m loading in Form_load:
OleDbConnection Con = new OleDbConnection();
Con.ConnectionString = Properties.Settings.Default.dbConTeste;
try
{
Con.Open();
OleDbCommand Cmm = new OleDbCommand();
Cmm.CommandText = "SELECT marca FROM tbmodelo";
Cmm.CommandType = CommandType.Text;
Cmm.Connection = Con;
OleDbDataReader DR;
DR = Cmm.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(DR);
DataView dv = new DataView(dt, "", "marca", DataViewRowState.OriginalRows);
comboBox1.DataSource = dv;
comboBox1.DisplayMember = "marca";
comboBox1.ValueMember = "";
}
catch
{
MessageBox.Show("error");
}
Con.Close();
the 2nd Combo I load in the Combobox1_leave event:
OleDbConnection Con1 = new OleDbConnection();
Con1.ConnectionString = Properties.Settings.Default.dbConTeste;
try
{
Con1.Open();
OleDbCommand Cmm = new OleDbCommand();
Cmm.CommandText = "SELECT " + comboBox1.Text + " FROM tbmodelo";
Cmm.CommandType = CommandType.Text;
Cmm.Connection = Con1;
OleDbDataReader DR;
DR = Cmm.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(DR);
DataView dv = new DataView(dt, "", comboBox1.Text, DataViewRowState.OriginalRows);
comboBox2.DataSource = dv;
comboBox2.DisplayMember = comboBox1.Text;
comboBox2.ValueMember = "";
}
catch
{
MessageBox.Show("error");
}
Con1.Close();
Does anyone indicate a simpler way to load Combos without the empty fields? or just delete the fields in Null. ?
Just for the record that if the field value is
NULL
(and not empty), will not work.– Jéf Bueno