Populating DropDowns

S

sck10

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
 
G

gh0st54

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
 
S

Saravana

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.
 
S

Steven Cheng[MSFT]

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.)
 
S

Steven Cheng[MSFT]

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.)
 

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,773
Messages
2,569,594
Members
45,118
Latest member
LatishaWhy
Top