Sheritlw
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.ApplicationBlock s.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
I am new to .Net and have been reading, reading, reading...
From a previous question, I found out about the Microsoft.ApplicationBlock
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
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.
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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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