Buona sera al forum,
è da giorni che giro intorno ad un problema senza trovare soluzione, praticamente carico i dati contenuti in un foglio excel in una datagridview e quando tento di salvare tutto il contenuto nel database mysql i dati non vengono salvati.
Premetto che ho costruito un applicazione per la gestione dei database mysql, quindi il datagridview che popolo non ha campi fissi.
Vi posto il codice per popolare il datagridview:
Public Sub Carica_Excel()
        Try
           Dim MyConnection As System.Data.OleDb.OleDbConnection
            Dim MyCommand As System.Data.OleDb.OleDbDataAdapter
            MyConnection = New System.Data.OleDb.OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & AppDomain.CurrentDomain.BaseDirectory + "\Excel\import.xls" & ";Extended Properties=Excel 8.0;")
            MyCommand = New System.Data.OleDb.OleDbDataAdapter("select * from [Report$]", MyConnection)
            MyCommand.TableMappings.Add("Table", "Import")
            m_DataSet = New System.Data.DataSet
            MyCommand.Fill(m_DataSet)
            frmImportExcel.dtgStructNewTbl.DataSource = m_DataSet.Tables(0)
            MyConnection.Close()
            frmImportExcel.Label1.Text = "TOTELE VOCI CARICATE " & frmImportExcel.dtgStructNewTbl.RowCount
        Catch ex As MySqlException
        End Try
    End Sub
adesso vi posto il codice per salvare i dati nel database:
 Public Sub CommitExcel(ByVal Database As String, ByVal Tabella As String, ByVal Tipo As String)
        If m_DataSet.HasChanges() Then
            Dim data_adapter As MySqlDataAdapter
            Dim Command_Builder As MySqlCommandBuilder
            Try
                'strSQL = "SELECT * FROM " & Id.Text & ""
                'strSQL = "SELECT * FROM '" & Database & "'.'" & Tabella & "'"
                strSQL = "SELECT * FROM " & Database & "." & Tabella & ""
                ' Create the DataAdapter.
                data_adapter = New MySqlDataAdapter(strSQL, Connection)
                ' Map Table to Contacts.
                data_adapter.TableMappings.Add("Table", Tabella)
                ' Make the CommandBuilder generate the
                ' insert, update, and delete commands.
                Command_Builder = New MySqlCommandBuilder(data_adapter)
                'Uncomment this code to see the INSERT,
                'UPDATE, and DELETE commands.
                'Debug.WriteLine("*** INSERT ***")
                'MsgBox(Command_Builder.GetInsertCommand.CommandText)
                'Debug.WriteLine("*** UPDATE ***")
                'MsgBox(Command_Builder.GetUpdateCommand.CommandText)
                'Debug.WriteLine("*** DELETE ***")
                'MsgBox(Command_Builder.GetDeleteCommand.CommandText)
                ' Save the changes.
                data_adapter.Update(m_DataSet)
                If Tipo = "ELIMINA" Then
                    'MsgBox("I dati selezionati sono stati eliminati")
                    Dim frm As New MessageOk
                    frm.lblTitolo.Text = "CONFERMA ELIMINAZIONE"
                    frm.lblTesto.Text = "I dati selezionati sono stati eliminati!"
                    frm._Tipo = "CONFERMA"
                    frm.ShowDialog()
                ElseIf Tipo = "SALVA" Then
                    'MsgBox("Operazione eseguita con successo")
                    Dim frm As New MessageOk
                    frm.lblTitolo.Text = "CONFERMA ELIMINAZIONE"
                    frm.lblTesto.Text = "Operazione eseguita con successo!"
                    frm._Tipo = "CONFERMA"
                    frm.ShowDialog()
                End If
            Catch ex As Exception
                MsgBox("Commit" & " " & ex.Message.ToString)
            End Try
        End If
    End Sub
Praticamente se popolo la datagridview da codice i dati nel database non vengono salvati, se li inserisco a mano scrivendo nelle varie celle invece i dati li salva.
Forse c'è qualcosa che non faccio?
riongrazio in anticipo