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
|
Private Sub BgWSQL_DoWork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BgWSQL.DoWork
Dim worker As BackgroundWorker = CType(sender, BackgroundWorker)
e.Result = SQLStore(SQLAlmDiag, worker, e)
End Sub
Public Function SQLStore(ByVal AlmDiag As DiagBufferData, ByVal worker As BackgroundWorker, ByVal e As DoWorkEventArgs) As Integer
Dim strConnexion As String = "Data Source=LOGIN; Integrated Security=SSPI;" + "Initial Catalog=maBaseDeTest"
Dim strRequete As String = "SELECT * FROM AlmDiag"
Dim oConnection As New SqlConnection(strConnexion)
Dim Result As Integer = Nothing
Try
If worker.CancellationPending Then
e.Cancel = True
Else
'Connexion sur la database
oConnection.Open()
Debug.Print("Ouverture de la connexion")
' Chargement de la liste des catégories dans oDataSet
Dim oSqlDataAdapter As New SqlDataAdapter(strRequete, oConnection)
Dim oDataSet As New DataSet("AlmDiag")
oSqlDataAdapter.Fill(oDataSet, "AlmDiag")
Debug.Print("Remplissage du Dataset")
oSqlDataAdapter.InsertCommand = New SqlCommand("INSERT INTO AlmDiag(Date,AcqErrMessage,DateApparition,DateDisparition,DiagItentifiant,EmplacementDfb,EtatAlarme,ImgDiag,NomInstanceDfb,TypeAlarmMessage,TypeDfb,Zone) Values(@Date,@AcqErrMessage,@DateApparition,@DateDisparition,@DiagItentifiant,@EmplacementDfb,@EtatAlarme,@ImgDiag,@NomInstanceDfb,@TypeAlarmMessage,@TypeDfb,@Zone)", oConnection)
oSqlDataAdapter.InsertCommand.Parameters.Add("@Date", SqlDbType.DateTime, 20, "Date")
oSqlDataAdapter.InsertCommand.Parameters.Add("@AcqErrMessage", SqlDbType.NVarChar, 200, "AcqErrMessage")
oSqlDataAdapter.InsertCommand.Parameters.Add("@DateApparition", SqlDbType.DateTime, 20, "DateApparition")
oSqlDataAdapter.InsertCommand.Parameters.Add("@DateDisparition", SqlDbType.DateTime, 20, "DateDisparition")
oSqlDataAdapter.InsertCommand.Parameters.Add("@DiagItentifiant", SqlDbType.NVarChar, 10, "DiagItentifiant")
oSqlDataAdapter.InsertCommand.Parameters.Add("@EmplacementDfb", SqlDbType.NVarChar, 200, "EmplacementDfb")
oSqlDataAdapter.InsertCommand.Parameters.Add("@EtatAlarme", SqlDbType.NVarChar, 200, "EtatAlarme")
oSqlDataAdapter.InsertCommand.Parameters.Add("@ImgDiag", SqlDbType.NVarChar, 10, "ImgDiag")
oSqlDataAdapter.InsertCommand.Parameters.Add("@NomInstanceDfb", SqlDbType.NVarChar, 10, "NomInstanceDfb")
oSqlDataAdapter.InsertCommand.Parameters.Add("@TypeAlarmMessage", SqlDbType.NVarChar, 10, "TypeAlarmMessage")
oSqlDataAdapter.InsertCommand.Parameters.Add("@TypeDfb", SqlDbType.NVarChar, 10, "TypeDfb")
oSqlDataAdapter.InsertCommand.Parameters.Add("@Zone", SqlDbType.Int, 8, "Zone")
Dim oDataRow As DataRow
oDataRow = oDataSet.Tables("AlmDiag").NewRow()
oDataRow("Date") = FormatDateTime(Now, DateFormat.ShortDate) & " " & FormatDateTime(Now, DateFormat.LongTime)
oDataRow("AcqErrMessage") = AlmDiag.AcqErrMessage
oDataRow("DateApparition") = AlmDiag.DateApparition
If AlmDiag.DateDisparition <> "" Then oDataRow("DateDisparition") = AlmDiag.DateDisparition
oDataRow("DiagItentifiant") = AlmDiag.DiagItentifiant
oDataRow("EmplacementDfb") = AlmDiag.EmplacementDfb
oDataRow("EtatAlarme") = AlmDiag.EtatAlarme
oDataRow("ImgDiag") = AlmDiag.ImgDiag
oDataRow("NomInstanceDfb") = AlmDiag.NomInstanceDfb
oDataRow("TypeAlarmMessage") = AlmDiag.TypeAlarmMessage
oDataRow("TypeDfb") = AlmDiag.TypeDfb
oDataRow("Zone") = AlmDiag.Zone
oDataSet.Tables("AlmDiag").Rows.Add(oDataRow)
Debug.Print("Ajout du nouvelle enregistrement")
'Mise à jour de la source de données à partir du DataSet
Result = oSqlDataAdapter.Update(oDataSet, "AlmDiag")
Debug.Print("Mise a jour de la base SQL")
End If
Catch ex As Exception
'Gestion des erreurs
Debug.Print(ex.Message)
Finally
'Fermeture de la connexion
oConnection.Close()
Debug.Print("Fermeture de la Database")
End Try
Debug.Print("Fin du background")
Return Result
End Function |
Partager