Advertisement
Guest User

Untitled

a guest
Nov 30th, 2015
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.34 KB | None | 0 0
  1. Public Sub createbackup()
  2. Using ofd As New FolderBrowserDialog
  3. If ofd.ShowDialog = DialogResult.OK Then
  4. Dim fileloc As String
  5.  
  6. fileloc = ofd.SelectedPath
  7.  
  8.  
  9. Dim datads As New DataSet
  10. Dim datad2 As New DataSet
  11.  
  12. If Not conn Is Nothing Then conn.Close()
  13. conn.ConnectionString = cstring()
  14.  
  15. Try
  16. conn.Open()
  17.  
  18.  
  19. Dim sql1 As String
  20. Dim command1 As MySqlCommand
  21. Dim adapter1 As New MySqlDataAdapter
  22. Dim sql2 As String
  23. Dim command2 As MySqlCommand
  24. Dim adapter2 As New MySqlDataAdapter
  25.  
  26. sql1 = "Select * from users"
  27. sql2 = "Select * from ips"
  28.  
  29.  
  30. command1 = New MySqlCommand(sql1, conn)
  31. command2 = New MySqlCommand(sql2, conn)
  32. adapter1.SelectCommand = command1
  33. adapter1.Fill(datads)
  34. adapter2.SelectCommand = command2
  35. adapter2.Fill(datad2)
  36.  
  37. Main.IPData.DataSource = datads.Tables(0)
  38. Main.UsersData.DataSource = datad2.Tables(0)
  39. Main.IPData.Columns(3).DefaultCellStyle.Format = "yyyy/MM/dd"
  40.  
  41.  
  42. Catch ex As Exception
  43. MsgBox(ex.ToString)
  44. End Try
  45. conn.Close()
  46.  
  47. Try
  48. Dim DTB = New DataTable, RWS As Integer, CLS As Integer
  49.  
  50. For CLS = 0 To Main.IPData.ColumnCount - 1 ' COLUMNS OF DTB
  51. DTB.Columns.Add(Main.IPData.Columns(CLS).Name.ToString)
  52. Next
  53.  
  54. Dim DRW As DataRow
  55.  
  56. For RWS = 0 To Main.IPData.Rows.Count - 1 ' FILL DTB WITH DATAGRIDVIEW
  57. DRW = DTB.NewRow
  58.  
  59. For CLS = 0 To Main.IPData.ColumnCount - 1
  60. Try
  61. ' save fix (need to format date proper
  62. ' If CLS = 4 Then
  63. DRW(DTB.Columns(CLS).ColumnName.ToString) = Main.IPData.Rows(RWS).Cells(CLS).Value.ToString
  64. ' else
  65. '
  66. 'End if
  67. Catch ex As Exception
  68. End Try
  69. Next
  70.  
  71. DTB.Rows.Add(DRW)
  72. Next
  73.  
  74.  
  75. Dim DTB2 = New DataTable, RWS2 As Integer, CLS2 As Integer
  76.  
  77. For CLS2 = 0 To Main.UsersData.ColumnCount - 1 ' COLUMNS OF DTB
  78. DTB2.Columns.Add(Main.UsersData.Columns(CLS2).Name.ToString)
  79. Next
  80.  
  81. Dim DRW2 As DataRow
  82.  
  83. For RWS2 = 0 To Main.UsersData.Rows.Count - 1 ' FILL DTB WITH DATAGRIDVIEW
  84. DRW2 = DTB2.NewRow
  85.  
  86. For CLS2 = 0 To Main.UsersData.ColumnCount - 1
  87. Try
  88. DRW2(DTB.Columns(CLS2).ColumnName.ToString) = Main.UsersData.Rows(RWS2).Cells(CLS2).Value.ToString
  89. Catch ex As Exception
  90.  
  91. End Try
  92. Next
  93.  
  94. DTB2.Rows.Add(DRW2)
  95.  
  96. Next
  97.  
  98. DTB.AcceptChanges()
  99. DTB2.AcceptChanges()
  100.  
  101. Dim DST As New DataSet
  102. Dim DST2 As New DataSet
  103. DST.Tables.Add(DTB)
  104. DST2.Tables.Add(DTB2)
  105. Dim FLE As String = "" & fileloc & "\users.xml" ' PATH AND FILE NAME WHERE THE XML WIL BE CREATED (EXEMPLE: C:\REPS\XML.xml)
  106. Dim FLE2 As String = "" & fileloc & "\ipaddresses.xml" ' PATH AND FILE NAME WHERE THE XML WIL BE CREATED (EXEMPLE: C:\REPS\XML.xml)
  107. DTB.WriteXml(FLE)
  108. DTB2.WriteXml(FLE2)
  109.  
  110. Catch ex As Exception
  111. ' MsgBox(ex.ToString)
  112. End Try
  113. updatedatagrid(Main.UsersData, Main.Emailbox.Text)
  114. End If
  115. End Using
  116.  
  117. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement