Following code to capture Category, Type Item works on its own but in
the context of my page I get the following error where I have
---->DropDownList2.DataSource = myCommand.ExecuteReader();
There is already an open DataReader associated with this Connection
which must be closed first
Any Ideas are greatly appreciated.
OleDbConnection myConnection = new
OleDbConnection(GetConnectionString());
myConnection.Open();
string SQL = @"SELECT distinct Category FROM CTI ORDER BY 1";
OleDbCommand myCommand = new OleDbCommand(SQL, myConnection);
DropDownList1.DataTextField="Category";
DropDownList1.DataValueField="Category";
DropDownList1.DataSource = myCommand.ExecuteReader();
DropDownList1.DataBind();
if(IsPostBack )
{
int i = 0;
foreach(ListItem li in DropDownList1.Items)
{
if( li.Value==Request.Form["DropDownList1"].ToString())
{
li.Selected = true;
}
i += 1;
}
SQL = @"SELECT distinct Type FROM CTI where
Category='"+Request.Form["DropDownList1"]+"' ORDER BY 1";
myCommand = new OleDbCommand(SQL, myConnection);
DropDownList2.DataTextField="Type";
DropDownList2.DataValueField="Type";
DropDownList2.DataSource = myCommand.ExecuteReader();
DropDownList2.DataBind();
if(Request.Form["DropDownList2"] != ".....")
{
i = 0;
foreach(ListItem li in DropDownList2.Items)
{
if( li.Value==Request.Form["DropDownList2"].ToString())
{
li.Selected = true;
}
i += 1;
}
SQL = @"SELECT distinct Item FROM CTI where
Type='"+Request.Form["DropDownList2"]+"' ORDER BY 1";
myCommand = new OleDbCommand(SQL, myConnection);
DropDownList3.DataTextField="Item";
DropDownList3.DataValueField="Item";
DropDownList3.DataSource = myCommand.ExecuteReader();
DropDownList3.DataBind();
if(Request.Form["DropDownList3"] != ".....")
{
i = 0;
foreach(ListItem li in DropDownList3.Items)
{
if( li.Value==Request.Form["DropDownList3"].ToString())
{
li.Selected = true;
}
i += 1;
}
}
}
Label1.Text= "Selected
"+Request.Form["DropDownList1"]+">>"+Request.Form["DropDownList2"]+">>"+Request.Form["DropDownList3"];
}
myConnection.Close();