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:
  1. Public Overloads Function ExecuteSql(ByVal SProcName As String, _
  2.                                         ByRef myDataReader As SqlDataReader) As Boolean
  3.  
  4.         ' Create a new command object
  5.         Dim myCommand As SqlCommand = CreateNoParamCommand(SProcName, CommandType.Text)
  6.  
  7.         ' Fill the DataReader object
  8.         Try
  9.             myDataReader = myCommand.ExecuteReader
  10.             System.Diagnostics.EventLog.WriteEntry(MODULE_NAME, "hi", Diagnostics.EventLogEntryType.Error)
  11.             Return True
  12.         Catch e As Exception
  13.             LogError(e)
  14.             Return False
  15.         End Try
  16.  
  17.     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:
  1. Private Function LoadGridje() As SqlDataReader
  2.  
  3.         Dim strSQL As String
  4.         Dim dr As SqlDataReader
  5.  
  6.         Dim DbAccess As New DataAccess()
  7.  
  8.         strSQL = "SELECT DISTINCT Afdeling FROM tblWerkposten"
  9.  
  10.         'Response.Write(DbAccess.ExecuteSql(strSQL, dr))
  11.         Try
  12.             If DbAccess.ExecuteSql(strSQL, dr) = True Then
  13.                 Return dr
  14.             Else
  15.                 Return Nothing
  16.             End If
  17.         Catch
  18.             Return Nothing
  19.         End Try
  20.  
  21.     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:
  1. Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  2.  
  3.         With cboAfdeling
  4.             .DataSource = LoadGridje()
  5.             .DataValueField = LoadGridje.GetName(0)
  6.             .DataBind()
  7.         End With
  8.  
  9.     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 !