Link to home
Start Free TrialLog in
Avatar of MasterWoodsman
MasterWoodsman

asked on

Save DataTable changes back to DB through wrapper class in library

I have an application that can use two different Databases, so I wrote a wrapper class for each Database.

Here is a snippet of the code from the wrapper library:
    Public Function ExecuteQuery(SQL As String) As DataTable
        Return GetDataTable(SQL, Nothing)
    End Function
    Private Function GetDataTable(ByVal query As String, ByVal ParamArray args() As MySqlParameter) As DataTable
        Dim dt As New DataTable
        Dim cmd As New MySqlCommand(query, GetConnection())
        If args IsNot Nothing Then
            For Each p As MySqlParameter In args
                cmd.Parameters.Add(p)
            Next p
        End If

        Dim da As New MySqlDataAdapter(cmd)
        da.Fill(dt)
        Return dt

    End Function

Open in new window


I can call this code from my main program and it works just fine.  The problem I have to writing back to the database.  For simple single commands I can handle this easily, but I have one situation where the user will be making multiple Insert/Edit/Delete operations on a large DataTable.  How can I simply dump these changes back into the database in one step?

I've never used DataAdapters and CommandBuilders but they look like what I need.  But how can I expose those from the library without the main application requiring a reference to the specific database dll?  (I cannot put a reference to the actual DB dll in my main code because of a version conflict.  Using a wrapper class was my solution to this problem).
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial