I writing a database communicatio class, I can get data out of it and return a dataTable but I can't give it back to update.
I added an argument "daAdapter to the Update function. But there's a few things I don't know about the dataadapter. Does it have to be the same dataAdapter that filled the dataTable in the first place ? I tried making daAdapter a global in the class but then I get an error about object not an instantce etc ... when I try to update. How can I write this so I don't have to return any dataadapters or feed them as argument for update statement ?
Many thanks, N3XuS
Code:
Public Function sSelect(ByVal strStoredProc As String) As DataTable
Dim mySqlCmd As New SqlCommand(strStoredProc)
Dim daDataAdapter As New SqlDataAdapter
Dim dtData As New DataTable
mySqlCmd = New SqlCommand
mySqlCmd.CommandType = CommandType.StoredProcedure
mySqlCmd.Connection = mySqlConn
mySqlCmd.CommandText = strStoredProc
daDataAdapter.SelectCommand = mySqlCmd
daDataAdapter.Fill(dtData)
Return dtData
End Function
Public Sub Update(ByVal dtValues As DataTable, ByVal daAdapter As SqlDataAdapter)
Dim xDataTable As DataTable = dtValues.GetChanges()
daAdapter.Update(xDataTable)
End Sub
I added an argument "daAdapter to the Update function. But there's a few things I don't know about the dataadapter. Does it have to be the same dataAdapter that filled the dataTable in the first place ? I tried making daAdapter a global in the class but then I get an error about object not an instantce etc ... when I try to update. How can I write this so I don't have to return any dataadapters or feed them as argument for update statement ?
Many thanks, N3XuS