By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,806 Members | 1,465 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,806 IT Pros & Developers. It's quick & easy.

Populating DropDowns

P: n/a
Hello,

I have two dropdown objects that I want to use the same datasource for each.
I tried the following, but it doesn't populate the second dropdown. Do I
need to close the OleDbDataReader and then re-open it to populate the second
dropdown object?

Thanks in advance,
sck10


'Populate the TerminationType combo box
'--------------------------------------
Dim spTerminationType As OleDb.OleDbDataReader
Dim prmTermType As OleDbParameter
Dim cmdTermType As New OleDb.OleDbCommand("spMySearch", cnnSearch)
cmdTermType.CommandType = CommandType.StoredProcedure

prmTermType = cmdTermType.Parameters.Add("@strParm01", OleDbType.VarChar)
: prmTermType.Value = "FindTerminationType"
prmTermType = cmdTermType.Parameters.Add("@strParm02", OleDbType.VarChar)
: prmTermType.Value = "NoParameter"
prmTermType = cmdTermType.Parameters.Add("@strParm03", OleDbType.VarChar)
: prmTermType.Value = "NoParameter"
prmTermType = cmdTermType.Parameters.Add("@strParm04", OleDbType.VarChar)
: prmTermType.Value = "NoParameter"

spTerminationType = cmdTermType.ExecuteReader()

'TerminationType 1
Me.ddlTerminationType1.DataSource = spTerminationType
Me.ddlTerminationType1.DataTextField = "TerminationType_ID"
Me.ddlTerminationType1.DataBind()

'TerminationType 2
Me.ddlTerminationType2.DataSource = spTerminationType
Me.ddlTerminationType2.DataTextField = "TerminationType_ID"
Me.ddlTerminationType2.DataBind()

spTerminationType.Close() : spTerminationType = Nothing
Nov 18 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
my guess would be that once the reader reaches the end you would have to
reset it a the beginning

why don't you use a dataset
"sck10" <sc***@online.nospam> wrote in message
news:eu**************@TK2MSFTNGP12.phx.gbl...
Hello,

I have two dropdown objects that I want to use the same datasource for each. I tried the following, but it doesn't populate the second dropdown. Do I
need to close the OleDbDataReader and then re-open it to populate the second dropdown object?

Thanks in advance,
sck10


'Populate the TerminationType combo box
'--------------------------------------
Dim spTerminationType As OleDb.OleDbDataReader
Dim prmTermType As OleDbParameter
Dim cmdTermType As New OleDb.OleDbCommand("spMySearch", cnnSearch)
cmdTermType.CommandType = CommandType.StoredProcedure

prmTermType = cmdTermType.Parameters.Add("@strParm01", OleDbType.VarChar) : prmTermType.Value = "FindTerminationType"
prmTermType = cmdTermType.Parameters.Add("@strParm02", OleDbType.VarChar) : prmTermType.Value = "NoParameter"
prmTermType = cmdTermType.Parameters.Add("@strParm03", OleDbType.VarChar) : prmTermType.Value = "NoParameter"
prmTermType = cmdTermType.Parameters.Add("@strParm04", OleDbType.VarChar) : prmTermType.Value = "NoParameter"

spTerminationType = cmdTermType.ExecuteReader()

'TerminationType 1
Me.ddlTerminationType1.DataSource = spTerminationType
Me.ddlTerminationType1.DataTextField = "TerminationType_ID"
Me.ddlTerminationType1.DataBind()

'TerminationType 2
Me.ddlTerminationType2.DataSource = spTerminationType
Me.ddlTerminationType2.DataTextField = "TerminationType_ID"
Me.ddlTerminationType2.DataBind()

spTerminationType.Close() : spTerminationType = Nothing

Nov 18 '05 #2

P: n/a
You cant use datareader for this purpose, you can move it to dataset.
Datareader can accessed for second time once it is open and moved to the
end.

--
Saravana
http://dotnetjunkies.com/WebLog/saravana/
www.ExtremeExperts.com
"sck10" <sc***@online.nospam> wrote in message
news:eu**************@TK2MSFTNGP12.phx.gbl...
Hello,

I have two dropdown objects that I want to use the same datasource for each. I tried the following, but it doesn't populate the second dropdown. Do I
need to close the OleDbDataReader and then re-open it to populate the second dropdown object?

Thanks in advance,
sck10


'Populate the TerminationType combo box
'--------------------------------------
Dim spTerminationType As OleDb.OleDbDataReader
Dim prmTermType As OleDbParameter
Dim cmdTermType As New OleDb.OleDbCommand("spMySearch", cnnSearch)
cmdTermType.CommandType = CommandType.StoredProcedure

prmTermType = cmdTermType.Parameters.Add("@strParm01", OleDbType.VarChar) : prmTermType.Value = "FindTerminationType"
prmTermType = cmdTermType.Parameters.Add("@strParm02", OleDbType.VarChar) : prmTermType.Value = "NoParameter"
prmTermType = cmdTermType.Parameters.Add("@strParm03", OleDbType.VarChar) : prmTermType.Value = "NoParameter"
prmTermType = cmdTermType.Parameters.Add("@strParm04", OleDbType.VarChar) : prmTermType.Value = "NoParameter"

spTerminationType = cmdTermType.ExecuteReader()

'TerminationType 1
Me.ddlTerminationType1.DataSource = spTerminationType
Me.ddlTerminationType1.DataTextField = "TerminationType_ID"
Me.ddlTerminationType1.DataBind()

'TerminationType 2
Me.ddlTerminationType2.DataSource = spTerminationType
Me.ddlTerminationType2.DataTextField = "TerminationType_ID"
Me.ddlTerminationType2.DataBind()

spTerminationType.Close() : spTerminationType = Nothing

Nov 18 '05 #3

P: n/a
Hi Sck10,

I think Gh0st54's suggestion is reasonable, a DataReader is a forward only
list and after we loop through all the records in it, the "Current"
position is pointed to the end of the records in it so the second time you
bind it to a dropdownlist, there is no data returned.
Alternatively, we can either
1. Close and get a new DataReader again as you said.

2. Or use DataAdapter to get a DataSet (contains DataTable) so that we can
bind DataTable to multi- databinding controls.

If you have anything unclear ,please feel free to post here.
Thanks.
Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #4

P: n/a
Hi Sck10,

Have you got any further progress or ideas on this issue? If there're
anything else we can help, please feel free to post here. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.