Is this the way to do Disconnected Dataset? Please Comment if there is something wrong with my code
Public Function OpenRs(ByVal DataSource As String, ByVal strSQL As String, ByVal ConnString As String) As DataSet
'Single DataSource
Try
Dim LiveConn As New SqlConnection(ConnString)
Dim PDataset As DataSet
Dim PCmd As New SqlCommand(strSQL, LiveConn)
varSingleDA = New SqlDataAdapter(PCmd)
Dim pCmdBldr As New SqlCommandBuilder(varSingleDA)
PDataset = New DataSet()
Me.varSingleDA.Fill(PDataset, DataSource)
'LiveConn.Close() '1. Do I have to Close & Dispose liveconn to Have Disconnected Data? Why Am i having a hard time Updating when LiveConn is Closed and Disposed?
'LiveConn.Dispose()
'varSingleDA.Dispose() '2
Return PDataset
RaiseEvent TransactionCompleted(True)
Catch err As SqlException
MsgBox(err.Message)
RaiseEvent TransactionCompleted(False)
Catch err As Exception
MsgBox(err.Message)
RaiseEvent TransactionCompleted(False)
End Try
End Function
Public Sub UpdateDataSet(ByVal VarDataset As DataSet, ByVal DataSource As String)
'Single DataSource
Try
If (Me.varSingleDA Is Nothing) Then
Exit sub
'OpenRsrs ??? 2. if i dispose varSingleDA in OpenRs should I Open it Here? Is disposing tha adaptor part of Disconnected data Trick?
End If
VarDataset.EnforceConstraints = False
Me.varSingleDA.Update(VarDataset, DataSource)
RaiseEvent TransactionCompleted(True)
Catch err As SqlException
MsgBox(err.Message)
RaiseEvent TransactionCompleted(False)
Catch err As Exception
MsgBox(err.Message)
RaiseEvent TransactionCompleted(False)
End Try
End Sub
Please help me with this, I am confused with this new technology
Proud To Be Pinoy