Imports Microsoft.VisualBasic Imports MySql.Data Imports MySql.Data.MySqlClient Imports System.Data Namespace MySqlDSTableAdapters Partial Public Class customersTableAdapter Dim m_isInitialized As Boolean = False Private Sub PrepareCommands() If Not m_isInitialized Then Me.ClearBeforeFill = True ' create a generic select command Dim sqlCommand As String sqlCommand = "Select * from " + _ Adapter.TableMappings(0).DataSetTable.ToString() Adapter.SelectCommand = _ New MySql.Data.MySqlClient.MySqlCommand(sqlCommand, Connection) ' now just by creating the commandbuidler associated with the adapter, we ' get the update, insert and delete commands Dim cb As MySql.Data.MySqlClient.MySqlCommandBuilder cb = New MySql.Data.MySqlClient.MySqlCommandBuilder(Adapter) m_isInitialized = True End If End Sub Public Function Update(ByVal dataTable As MySqlDS.customersDataTable) As Boolean ' call prepare commands to make sure we have the insert/update/delete commands ' set up PrepareCommands() Dim res As Integer = 0 Dim conn As MySqlConnection = Nothing Try ' open the connection just in case it was not open by the time we get called If Adapter.SelectCommand.Connection.State <> ConnectionState.Open Then ' if we are opening the connection the we should close it so ' store it in a local connection conn = Adapter.SelectCommand.Connection conn.Open() End If res = Me.Adapter.Update(dataTable) Finally ' if we open the connection we should close it If conn IsNot Nothing And conn.State <> ConnectionState.Closed Then conn.Close() End If End Try ' we are done! Return res End Function End Class End Namespace