Problem with OleDB - Dynamic DropDownList

M

mo

Hi,
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();
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top