I have a combobox and a gridview. whenever an item from the combobox is selected , the gridview should be populated with related records.
My question is how can we refresh the datagridview with new data and remove the old one.
Right now when i click on combobox item A , the gridview displays item A records.
Then when i select combobox item B, the gridview displays Item A and B records.
I only want item B records to be displayed
Dipankar BiswasPosted May 11, 2015, 8:35 AM
try.. celect change event..
private void search_d()
{
if (connectiondb.State == ConnectionState.Closed)
{
connectiondb.Open();
}
//Select_sub_or_date_for_result frm = new Select_sub_or_date_for_result();
string all_data_query = "Select Main_id,SName,Mrk_R,Mrk_W,mark from tbl_result where sub='" + comboBox2.Text.Trim() + "' and Exam_date='" + dateTimePicker2.Text + "' ";
com = new OleDbCommand(all_data_query, connectiondb);
com.CommandType = CommandType.Text;
OleDbDataAdapter da = new OleDbDataAdapter(com);
DataTable dt = new DataTable();
da.Fill(dt);
this.dataGridView1.DataSource = dt;
connectiondb.Close();
}