Global dropdownlist populating function using oledb

liunx

Guest
Hi all here is a class i just created after doing some decent research and noticed that byref is not returning the new list items to the object thats calling it.
Imports System.web
Imports System.Web.HttpContext
Imports System.Data.OleDb
Imports System.IO

Public Class DB_mainLib
Shared Function PrintAgencyList(ByVal Db As Object, ByVal SelectedAgency As String, ByRef DDObj As DropDownList)
Dim sSQL
Dim sSelected
Dim cmd As New OleDbCommand
Dim Dr As OleDbDataReader
Dim GetRecords As OleDb.OleDbDataReader

sSQL = "exec sp_ComboAgency " & Current.Session("OPID")
cmd = New OleDb.OleDbCommand(sSQL, Db)
GetRecords = cmd.ExecuteReader()

While Not GetRecords.Read()
Dim litem As New ListItem
If SelectedAgency = GetRecords("Agency") & "" Then
litem.Selected = True
Else
litem.Selected = False
End If
litem.Text = GetRecords("Agency")
litem.Value = GetRecords("Agency")

DDObj.Items.Add(litem)

End While
GetRecords.Close()



End Function
End Class

and the call looks like this which i put in the page_load in another aspx page:

sConnString = Application("Conn2_ConnectionString")
Conn = New OleDb.OleDbConnection(sConnString)
Conn.Open()
DB_mainLib.PrintAgencyList(Conn, "1", Agency)


ThanksSorry i all found the mistake its the While Not GetRecords.Read()
NOT in there causign to get out of loop
sorry again close this
 
Back
Top