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

Visual Basic.NET

Avatar of undefined
Last Comment
Priest04
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
Sheritlw
Flag of United States of America image

ASKER

I believe it does close it, but I really want to know more about this library.
Avatar of Priest04
Priest04
Flag of Serbia image

If you have source code, then you can easily look in it.
Avatar of Sheritlw
Sheritlw
Flag of United States of America image

ASKER

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.
Avatar of Priest04
Priest04
Flag of Serbia image

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

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Priest04
Priest04
Flag of Serbia image

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

Visual Basic.NET
Visual Basic.NET

Visual Basic .NET (VB.NET) is an object-oriented programming language implemented on the .NET framework, but also supported on other platforms such as Mono and Silverlight. Microsoft launched VB.NET as the successor to the Visual Basic language. Though it is similar in syntax to Visual Basic pre-2002, it is not the same technology,

96K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo