• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1249
  • Last Modified:

MySQL Adapter Update question

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.
  • 2
1 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

preserver3Author Commented:
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.

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


Featured Post

NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now