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
|
Try
ForEach FileToRestore AsStringInMe.chlb.CheckedItems
Dim objSQLConn AsNew SqlConnection("Data Source=" & SelectedServer & ";Initial Catalog=" & Me.cboDatabase.Text & ";Persist Security Info=True;User ID=" & Username & ";Password=" & Password)
Dim objAdapter As SqlDataAdapter
Dim objDataRow, objDBRow As DataRow
Dim objDSXML AsNew DataSet()
Dim objDSDBTable AsNew DataSet()
Dim ObjCmdBuilder As SqlCommandBuilder
ProgressBar.Maximum = Me.chlb.CheckedItems.Count
ProgressBar.Step = 1
objDSXML.ReadXml(TempFolder & "arcam\" & FileToRestore & ".txt")
objSQLConn.Open()
Dim i AsInteger = 0
Dim j AsInteger = 0
For i = 0 To objDSXML.Tables.Count - 1
objAdapter = New SqlDataAdapter("SELECT * FROM " & "[" & objDSXML.Tables(i).TableName & "]", objSQLConn)
objAdapter.Fill(objDSDBTable, objDSXML.Tables(i).TableName)
Application.DoEvents()
ForEach objDataRow In objDSXML.Tables(i).Rows
With objDSDBTable.Tables(i)
objDBRow = .NewRow()
For j = 0 To objDSXML.Tables(i).Columns.Count - 1
objDBRow(j) = objDataRow(j)
Application.DoEvents()
Next
.Rows.Add(objDBRow)
EndWith
ObjCmdBuilder = New SqlCommandBuilder(objAdapter)
objAdapter.Update(objDSDBTable, objDSXML.Tables(i).TableName)
Application.DoEvents()
Next
Application.DoEvents()
Next
objSQLConn.Close()
Next
MsgBox("Restauration terminée avec succès", MsgBoxStyle.Information, "Fin de la restauration")
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, "Erreur lors de la restauration des données")EndTry |
Partager