|
I have a combobox on my form. It is attached to a dataset and uses the values from datetimepicker's in the where clause. When the form opens, everything is retrieved correctly. When I change the value of the datetimepicker I want to empty the combobox and retrieve the new values. I set my datasource to null, and clear the items which works fine, but I am never able to set the datasource back to the combobox even though I specify it, my combobox is empty. My dataset has the data, I can see that in the debugger.
Code in Value_Changed event looks like the following, I really hope someone can help:
PO_ComboBox.DataSource = null;
PO_ComboBox.Items.Clear();
this.po_da.SelectCommand = new System.Data.OleDb.OleDbCommand(@"SELECT DISTINCT RelatedKey FROM ContainerHeader WHERE (CreateDate BETWEEN '" + dateTimePicker1.Value.ToShortDateString() + "' AND '" + dateTimePicker2.Value.ToShortDateString() + "') ORDER BY RelatedKey", oleDbConnection1);
PO_ComboBox_Fill_DataSet();
THE FUNCTION CALLED LOOKS LIKE THE FOLLOWING:
private void PO_ComboBox_Fill_DataSet()
{
try
{
this.oleDbConnection1.Open();
po_da.Fill(po_ds, "ContainerHeader");
}
}
catch (System.Exception fillException)
{
throw fillException;
}
finally
{
this.oleDbConnection1.Close();
}
PO_ComboBox.DisplayMember = "RelatedKey";
PO_ComboBox.ValueMember = PO_ComboBox.DisplayMember;
PO_ComboBox.DataSource = po_ds.Tables["ContainerHeader"];
|