Advanced problem with function handling
Hello everybody,
I just wrote a datalayer with help from a wrox book. This layer works fine but I have a question about it.
This is my data layer :
VB Code:
Public Overloads Function ExecuteSql(ByVal SProcName As String, _
ByRef myDataReader As SqlDataReader) As Boolean
' Create a new command object
Dim myCommand As SqlCommand = CreateNoParamCommand(SProcName, CommandType.Text)
' Fill the DataReader object
Try
myDataReader = myCommand.ExecuteReader
System.Diagnostics.EventLog.WriteEntry(MODULE_NAME, "hi", Diagnostics.EventLogEntryType.Error)
Return True
Catch e As Exception
LogError(e)
Return False
End Try
End Function
As you can see, I made a logging in the event log to see each time a dbase connection has been made.
I wrote following function to make a separate layer. This function returns me the datalayer.
VB Code:
Private Function LoadGridje() As SqlDataReader
Dim strSQL As String
Dim dr As SqlDataReader
Dim DbAccess As New DataAccess()
strSQL = "SELECT DISTINCT Afdeling FROM tblWerkposten"
'Response.Write(DbAccess.ExecuteSql(strSQL, dr))
Try
If DbAccess.ExecuteSql(strSQL, dr) = True Then
Return dr
Else
Return Nothing
End If
Catch
Return Nothing
End Try
End Function
Right now I want to bind a combobox on my function. All this works perfect, except when I call the DataValueField, which needs to give me the values of the datareader, then my connection has been made twice (I can see this in my event log) :(
VB Code:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
With cboAfdeling
.DataSource = LoadGridje()
.DataValueField = LoadGridje.GetName(0)
.DataBind()
End With
End Sub
I hope someone knows how I can work around this cause it's a pretty though one and I adore performance ;)
Thanks in advance !
Bjorn
ps : if it isn't clear enough, please return a message !