Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems updating from datatable changes... 1

Status
Not open for further replies.

N3XuS

Programmer
Mar 1, 2002
339
BE
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.
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
 
You don't need to use the same instance of the data adapter.
You do need it configured to update,insert,delete.
It is done with one drag of the mouse when you drag your data table from server explorer onto a component or page.

Or use the wizard.


Both options save hours of typing.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top