Advertisement
George_Nikou

tmp-form

Oct 23rd, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. Imports MySql.Data.MySqlClient
  2.  
  3. Public Class Form1
  4.  
  5.  
  6. Private connectionString = "server=localhost;user id=root;password=;database=test;"
  7. Private connect As MySqlConnection
  8. Dim db As New DBManager
  9.  
  10. Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  11.  
  12. db.testConnection()
  13.  
  14. Try
  15. Me.connect = New MySqlConnection(connectionString)
  16. Me.connect.Open()
  17.  
  18.  
  19. Dim query As String = "SELECT * FROM table1"
  20. Dim datatable As New DataTable()
  21.  
  22. Dim cmd As New MySqlCommand(query, Me.connect)
  23. Dim adapter As New MySqlDataAdapter(cmd)
  24.  
  25. adapter.Fill(datatable)
  26.  
  27. With Me.dgv_form1
  28. .DataSource = datatable
  29.  
  30. .Columns(0).HeaderText = "ID"
  31. .Columns(1).HeaderText = "Firstname"
  32.  
  33. .Columns(0).Width = 75
  34. .Columns(1).Width = 250
  35. End With
  36.  
  37.  
  38. Catch ex As Exception
  39. MsgBox(ex.Message, MsgBoxStyle.Critical, "Connection Failed")
  40. End Try
  41.  
  42. End Sub
  43.  
  44. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles btn_add.Click
  45. Dim ob As New TestBean(50, "Davis luther")
  46. db.addUser(ob)
  47.  
  48. db.testConnection()
  49.  
  50. Try
  51. Me.connect = New MySqlConnection(connectionString)
  52. Me.connect.Open()
  53.  
  54.  
  55. Dim query As String = "SELECT * FROM table1"
  56. Dim datatable As New DataTable()
  57.  
  58. Dim cmd As New MySqlCommand(query, Me.connect)
  59. Dim adapter As New MySqlDataAdapter(cmd)
  60.  
  61. adapter.Fill(datatable)
  62.  
  63. With Me.dgv_form1
  64. .DataSource = datatable
  65.  
  66. .Columns(0).HeaderText = "ID"
  67. .Columns(1).HeaderText = "Firstname"
  68.  
  69. .Columns(0).Width = 75
  70. .Columns(1).Width = 250
  71. End With
  72.  
  73.  
  74. Catch ex As Exception
  75. MsgBox(ex.Message, MsgBoxStyle.Critical, "Connection Failed")
  76. End Try
  77.  
  78. End Sub
  79.  
  80. Private Sub btn_edit_Click(sender As Object, e As EventArgs) Handles btn_edit.Click
  81. Dim ob As New TestBean(6, "Georges")
  82. db.editUser(ob)
  83. End Sub
  84. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement