controls sharing one OleDbDataReader

  • Thread starter Thread starter Steven K
  • Start date Start date
S

Steven K

Hello,

I am using the following code which works. My question is does the
OleDbDataReader need to be closed and then re-executed for every control?
Is there a more effecient way of doing this other than using a loop?

Thanks in advance, Steven


Dim spTermType As OleDb.OleDbDataReader
Dim prmTermType As OleDbParameter
Dim cmdTermType As New OleDb.OleDbCommand("sp_web_Search", cnnSearch)
cmdTermType.CommandType = CommandType.StoredProcedure

spTermType = cmdTermType.ExecuteReader()
ddlType1.DataSource = spTermType
ddlType1.DataTextField = "TerminationType_ID"
ddlType1.DataTextField = "TerminationType_ID"
ddlType1.DataBind()

spTermType.Close() : spTermType = Nothing
spTermType = cmdTermType.ExecuteReader()
ddlType2.DataSource = spTermType
ddlType2.DataTextField = "TerminationType_ID"
ddlType2.DataTextField = "TerminationType_ID"
ddlType2.DataBind()
 
If you think many controls share common data, you could create another
control that just retrieves data and "feeds" it to other controls (say, a
dataset/datatable). But, if your controls are independent, the way you are
doing it is the best way to go.
 
Back
Top