Link to home
Start Free TrialLog in
Avatar of Sheritlw
SheritlwFlag for United States of America

asked on

Using SqlHelper.ExecuteDataset in VB.Net

Hi Experts,

I am new to .Net and have been reading, reading, reading...
From a previous question, I found out about the Microsoft.ApplicationBlocks.Data and am trying to use this to access my data.
I have created the code below to fill grids (fpSpread).  
Everything I have read says that you always close the connection, but with the sqlhelper I was wondering if this will close the connection for me and if this code is correct?
Thanks,
Sheri

Public Shared ReadOnly Property ConnectionString() As String
        Get
            Return ConfigurationManager.AppSettings("ConnectionString")
 
        End Get
    End Property
 
Public Function GetDataSetGrd(ByVal strSQL As String) As DataSet
        Dim ds As New DataSet
       
        Try
            ds = SqlHelper.ExecuteDataset(AppConfig.ConnectionString, _
                                CommandType.Text, strSQL)
            Return ds
            Exit Try
 
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            Return Nothing
 
        Finally
            If Not ds Is Nothing Then
                ds.Dispose()
 
            End If
        End Try
 
    End Function

Open in new window

Avatar of Priest04
Priest04
Flag of Serbia image

The code you have posted is creating the connection object, based on the connection string that you have provided. Since you dont hold the reference to the created connection object, you cannot tell whether it is opened or closed. I have never used this library, but I assume it does close the connection - otherwise it would be a huge bug/memory leak.

Generally speaking, when you use dataadapter to create dataset object (using Fill method), if the connection was closed, it will close it after it has filled dataset. If it was opened, it would leave it opened. If this class uses internally dataadapter, then, as you already guessed,  it will close it.

Goran
Avatar of Sheritlw

ASKER

I believe it does close it, but I really want to know more about this library.
If you have source code, then you can easily look in it.
Hi Priest,

Like I said before, I have read everything I could find on this subject.  I was hoping that an expert could help me figure out how to use this correctly.
An expert would rarely used something that he doesn't have source code for, unless there is not other option.  If uou do not have documentation, nor source code, then I suggest you should better stick with some other framework.
ASKER CERTIFIED SOLUTION
Avatar of Priest04
Priest04
Flag of Serbia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
One thing more: you do not need to instantiate dataset object, this will be done by the ExecuteDataSet method. So, this is enough



Dim ds As DataSet

Open in new window