Don't close the DataReader until you have
bound the controls:
private void BindListBox(DropDownList listControl, string Sql, string dataText,
string dataValue, string listText)
OleDbDataReader dr;
dr = DBUtility.GetDataReader(Sql);
if(dr != null)
{
if(dr.FieldCount > 0)
{
listControl.DataSource = dr;
listControl.DataTextField = dataText;
listControl.DataValueField = dataValue;
listControl.DataBind();
listControl.Items.Insert(0, listText);
listControl.SelectedIndex = 0;
}
}
dr.Close();
}
To get DataReader:
public static OleDbDataReader GetDataReader(string SQLString)
{
OleDbConnection cn = new OleDbConnection(DBConnString);
OleDbDataReader dr;
try
{
cn.Open();
OleDbCommand cmd = cn.CreateCommand();
cmd.CommandText = SQLString;
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
}
catch (Exception e)
{
throw e;
}
return dr;
}