1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
#Region "Base Generateur*******************"
Public DataAdapterIdPC As MySqlDataAdapter = New MySqlDataAdapter()
Dim CmdBuildIdPC As MySqlCommandBuilder = New MySqlCommandBuilder(DataAdapterIdPC)
Public DataSetIdPC As DataSet = New DataSet("cleidentification")
Private Sub ChargerBaseIdPC()
Try
CmdBuildIdPC.QuotePrefix = "["
CmdBuildIdPC.QuoteSuffix = "]"
Catch : End Try
If DataSetIdPC.Tables("cleidentification") IsNot Nothing Then
If Application.OpenForms.Count > 3 And Rechargement = False Then Exit Sub
DataSetIdPC.Tables("cleidentification").Clear()
End If
Dim Req As String
Dim Cmd As MySqlCommand
Req = "SELECT * FROM cleidentification"
Cmd = New MySqlCommand(Req, CnxIdPC) 'recup les données de Mysql
DataAdapterIdPC.SelectCommand = Cmd ' DataAdaptater fait la laison entre le dataset et Mysql
DataAdapterIdPC.Fill(DataSetIdPC, "cleidentification") 'le Fill permet d'extraire les données du Dataset et les mettres dans la datatable "cleidentification"
End Sub
Sub MAJIdPC()
If DataSetIdPC.Tables("cleidentification") IsNot Nothing Then
If DataSetIdPC.Tables("cleidentification").GetChanges Is Nothing Then Exit Sub
MAJ: Try
CmdBuildIdPC.GetUpdateCommand()
DataAdapterIdPC.Update(DataSetIdPC, "cleidentification") 'Repercute sur La table mysql les données modifié dans le dataset ''''Contient le dataset avec les données modif et l'objet datatable qui contient les modif a extraire
Rechargement = True : ChargerBaseIdPC() : Rechargement = False
Catch ex As Exception
If ErreurMAJBases = False Then ErreurMAJBases = True : GoTo MAJ
TextBox1.Text = ex.Message & vbCrLf & vbCrLf & "Link" & vbCrLf & ex.HelpLink & vbCrLf & vbCrLf & "StackTrace" & vbCrLf & vbCrLf & ex.StackTrace & vbCrLf & vbCrLf & "Source" & vbCrLf & vbCrLf & ex.Source
MsgBox("Erreur message : " & vbCrLf & ex.Message & vbCrLf & vbCrLf & "Link" & vbCrLf & ex.HelpLink & vbCrLf & vbCrLf & "StackTrace" & vbCrLf & vbCrLf & ex.StackTrace & vbCrLf & vbCrLf & "Source" & vbCrLf & vbCrLf & ex.Source, MsgBoxStyle.Critical, "Critique")
ErreurMAJBases = False
End Try
End If
End Sub
#End Region
#Region "Affiche données*******************"
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
With Me.DataGrid1
.RowsDefaultCellStyle.BackColor = Color.White
.AlternatingRowsDefaultCellStyle.BackColor = Color.AliceBlue
End With
RecupDonnées()
ConnexionIdPC()
ChargerBaseIdPC()
DataGrid1.DataSource = DataSetIdPC.Tables("cleidentification")
End Sub
#End Region
#Region "Enregistrement********************"
Private Sub BT_Envoyer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BT_Envoyer.Click
Dim MyNewRow As DataRow = DataSetIdPC.Tables("cleidentification").NewRow
Try
MyNewRow("processeur") = TB_cléProc2.Text
MyNewRow("bios") = TB_cléBIOS2.Text
MyNewRow("cartevideo") = TB_cléCG2.Text
MyNewRow("disquedur") = TB_cléDD2.Text
DataSetIdPC.Tables("cleidentification").Rows.Add(MyNewRow)
MAJIdPC()
Catch err As Exception
MsgBox(err.Message & "error")
DataSetIdPC = New DataSet
DataAdapterIdPC = New MySqlDataAdapter("SELECT * FROM cleidentification", CnxIdPC)
DataAdapterIdPC.Fill(DataSetIdPC, "cleidentification")
DataGrid1.DataSource = DataSetIdPC.Tables("cleidentification")
Exit Sub
End Try
End Sub
#End Region |
Partager