473,386 Members | 1,883 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Problem with OleDB - Dynamic DropDownList

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();
Nov 18 '05 #1
0 932

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Kalyani | last post by:
Hi, I have a page with one DropDownList and a Placeholder.This placeholder wil contain either a textbox or a DropDownList depending upon the value in previous DropDownList. Also there is a Submit...
1
by: Kalyani | last post by:
Hi, I have a page with one DropDownList and a Placeholder.This placeholder wil contain either a textbox or a DropDownList depending upon the value in previous DropDownList. Also there is a Submit...
0
by: Ben | last post by:
Hi, It's about a database containing (for simplifying) three fields: 'placenr' (primary key), 'place' and 'color'. The records are updatable (Edit/Update button) in a gridview. For updating the...
4
by: pankajsingh5k | last post by:
Hi guys, These question is for all the experts... Please help me before my brain explodes The problem is again with the formview control.. I have a formview and i have to use it that...
2
by: pankajsingh5k | last post by:
Dear All, Please help me... I had read an article to lazy load a tab in a tabcontainer using an update panel on http://mattberseth.com/blog/2007/07/how_to_lazyload_tabpanels_with.html ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.