Buongiorno al forum,
stò sviluppando un programma di gestione dei database MYSQL, per attagliarlo alle mie esigenze.
Mi sono creato una classe dove gestisco l'intera gestione dei database con le Create Database, Table, StoredProcedure ecc, fin qui nessun problema, nella lettura dei dati nei datagridvew ho creato un datatable sempre nella classe che ho descritto vi posto il codice:
Public Function MySqlDirectQuery(ByVal Testo As String) As DataTable
Dim adapter As New MySqlDataAdapter
Dim oTable As New DataTable
If Not Flag Then
Return Nothing
Exit Function
End If
Try
Testo = CheckOriginalString(Testo)
myCommand.CommandType = CommandType.Text
myCommand.CommandText = Testo
adapter.SelectCommand = myCommand
oTable.Clear()
adapter.Fill(oTable)
Return oTable
Catch ex As MySqlException
Throw
Finally
If Not adapter Is Nothing Then adapter.Dispose()
If Not oTable Is Nothing Then oTable.Dispose()
End Try
End Function
Nei form lo richiamo con questo semplice codice:
Dim colName As String = dtgTabella.Columns(e.ColumnIndex).Name
Dim i As Integer = dtgTabella.CurrentRow.Index
dt = cls.MySqlDirectQuery("SELECT * FROM " & ComboBox1.SelectedValue.ToString & "." & dtgTabella.Item(1, i).Value & "")
dtgDati.AutoGenerateColumns = True
dtgDati.DataSource = dt
Adesso mi sono arenato per quanto riguarda l'aggiornamento dei dati INSERT e UPDATE ho provato svariati codici per l'aggiornamento senza risultati l'ultimo codice che ho scritto è questo:
Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
Dim da As New MySqlDataAdapter
' First process deletes.
da.Update(dt.Select(Nothing, Nothing, DataViewRowState.Deleted))
' Next process updates.
da.Update(dt.Select(Nothing, Nothing, DataViewRowState.ModifiedCurrent))
' Finally, process inserts.
da.Update(dt.Select(Nothing, Nothing, DataViewRowState.Added))
End Sub
Avrei bisogno di un aiutino, ringrazio anticipatamente
Modificato da Mau67 il 11 agosto 2021 13:33 -
Modificato da Mau67 il 11 agosto 2021 15:59 -