Solved

Save DataTable changes back to DB through wrapper class in library

Posted on 2015-02-09
1
34 Views
Last Modified: 2016-01-11
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).
0
Comment
Question by:MasterWoodsman
1 Comment
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 40603410
If your tables have primary keys, then you can use the MySqlCommandBuilder with the MySqlDataAdapter to auto-generate the CRUD commands for the data adapter.

Please describe the "version conflict" comment that you made.  Do you need two different versions of the same database assembly?
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword This is an old article.  Instead of using the MySQL extension that was used in the original code examples, please choose one of the currently supported database extensions instead.  More information is available here: MySQLi / PDO (http://…
I have been using r1soft Continuous Data Protection (http://www.r1soft.com/linux-cdp/) for many years now with the mySQL Addon and wanted to share a trick I have used several times. For those of us that don't have the luxury of using all transact…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question