Mocella,
FYI, I'm using SQL Server, Stored Procs w/ no parameters.
By "..a function that takes your control .." do you mean pass-in the control? I'd prefer to only pass-in the stored proc name and have the function return a populated object to which the listbox/combo could then bind to.
Also, to return a datareader, the function "GetDatareader" must be declared as datareader. No? I've tried that but it's not a valid type.
FYI, I've been working on a function that will return a DataTable (all new to me!). Here's what it looks like so far:
Public Overloads Overrides Function GetDataReader(ByVal storedProcName As String) As DataTable
GetDataReader = New DataTable("ListTable")
'Create the connection to the database...
Dim cnSQLConnection As New SqlConnection(GenericDataAccessProvider._Dbstring)
cnSQLConnection.Open()
'Create the readers command
Dim command As New SqlCommand(storedProcName, cnSQLConnection)
command.CommandType = CommandType.StoredProcedure
command.CommandText = storedProcName
'Create the DataReader object
Dim SQLReader As SqlDataReader
Try
'Set up the DataTable
Dim displayMemberCol As DataColumn = New DataColumn
Dim valueMemberCol As DataColumn = New DataColumn
With valueMemberCol
.DataType = System.Type.GetType("System.Integer")
.ColumnName = "Key"
End With
With displayMemberCol
.DataType = System.Type.GetType("System.String")
.ColumnName = "Text"
End With
GetDataReader.Columns.Add(valueMemberCol)
GetDataReader.Columns.Add(displayMemberCol)
'Populate the Reader
SQLReader = command.ExecuteReader()
Do While SQLReader.Read
GetDataReader.NewRow()
Loop
Catch ex As Exception
MsgBox("The Following Error Occurred: " & ex.Message, , "Class -MSSQLServer.GetDataReader()")
Finally
End Try
SQLReader.Close()
cnSQLConnection.Close()
End Function
Thanks!