I am trying to filter a Datagirdview with combobox value
the code is here,
OleDbDataAdapter dt = new OleDbDataAdapter();
DataTable tt = new DataTable();
BindingSource bs = new BindingSource();
OleDbConnection con = new OleDbConnection();
con.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Rock.accdb";
con.Open();
string query = "SELECT * FROM bankdet WHERE [date] Between @a AND @b";
OleDbCommand cmd = new OleDbCommand(query, con);
cmd.Parameters.AddWithValue("@a", dateTimePicker1.Text);
cmd.Parameters.AddWithValue("@b", dateTimePicker2.Text);
dt.SelectCommand = cmd;
dt.Fill(tt);
bs.DataSource = tt;
dataGridView1.DataSource = bs;
dt.Update(tt);
con.Close();
foreach (DataGridViewRow row in dataGridView1.Rows)
{
string s = row.Cells[1].Value.ToString();
if (!s.StartsWith(comboBox2.Text, true, null))
{
CurrencyManager currencyManager1 = (CurrencyManager)BindingContext[dataGridView1.DataSource];
currencyManager1.SuspendBinding();
row.Visible = false;
currencyManager1.ResumeBinding();
}
else
row.Visible = true;
}
the first half fill the datagirdview with values, the sencond one must filter it... instead i am getting error at
string s = row.Cells[1].Value.ToString();
any idea why?