Solved

Save DataTable changes back to DB through wrapper class in library

Posted on 2015-02-09
1
36 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

Webinar: Security & Encryption in the MySQL world

Join Percona’s Solutions Engineer, Dimitri Vanoverbeke as he presents “Security and Encryption in the MySQL world” on Thursday, July 6, 2017 at 7:00 am PDT / 10:00 am EDT (UTC-7).

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Containers like Docker and Rocket are getting more popular every day. In my conversations with customers, they consistently ask what containers are and how they can use them in their environment. If you’re as curious as most people, read on. . .
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

695 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