MySQL Adapter Update question

Posted on 2004-11-09
Last Modified: 2011-10-03
I'm using the byteFX derived ASP.NET compliant MySQL components in Visual Studio 2003 to talk to several tables including a coupt of joined tables.  My problem is in updating data and how to form the command text of the Update command for my adapter.  My Select command for instance, is easy
SELECT * FROM table_01t

My Inser Statement is easy

INSERT INTO table_01t (x,y,z) VALUES (Stringx,Stringy,Stringz)

where Stringx, Stringy and Stringz are derived from javascript based controls on a web page and then passed as string to the C# code on the server side.

My update gets tricky, and i'm not certain how to make my update command work properly... The adapter apparently wants it in this form MySQLAdaptert01.Update(DataSet,Tablename); and then somehow uses the update command I've included to update the datatable.  My problem is in generating the update command on the fly so I can update the right table, the right fields and from the right dataset based upon the users inputs.  I'm just not comfortable building the update string when I can't see how it will be used.

I have three tables with 75 columns aggregate(ie 21, 26, 28), and in the worst case scenario, I'd update every field in every table except for the ID strings of each, and in the simplest situation, i'd only be changing 1 field, in one column, in one table.
Question by:preserver3
    LVL 28

    Accepted Solution

    Hi preserver3,

    have you tried to use OledbCommandBuilder or OdbcCommandBuilder

    here is a sample taken from msdn:
    Public Shared Function SelectOdbcSrvRows(myConnection As String, mySelectQuery As String, myTableName As String) As DataSet
        Dim myConn As New OdbcConnection(myConnection)
        Dim myDataAdapter As New OdbcDataAdapter()
        myDataAdapter.SelectCommand = New OdbcCommand(mySelectQuery, myConn)
        Dim cb As OdbcCommandBuilder = New OdbcCommandBuilder(myDataAdapter)


        Dim ds As DataSet = New DataSet
        myDataAdapter.Fill(ds, myTableName)

        ' Code to modify data in DataSet here

        ' Without the OdbcCommandBuilder this line would fail.
        myDataAdapter.Update(ds, myTableName)

    End Function 'SelectOdbcSrvRows

    LVL 1

    Author Comment

    MySql.Data.MySqlClient.MySqlCommandBuilder Table_01CommandBuilder = new MySql.Data.MySqlClient.MySqlCommandBuilder(Table_01Adapter,true);

    is the command builder native to the MySQL .Net connector and works faster and more reliably than the ole or the odbc.

    Thanks, you lead me in the right direction.

    LVL 28

    Expert Comment

    sorry, i have not used it and can not say that


    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
    A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    746 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

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now