Solved

Save DataTable changes back to DB through wrapper class in library

Posted on 2015-02-09
1
35 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

730 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