Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports MySql.Data.MySqlClient
- Public Class Form1
- Private connectionString = "server=localhost;user id=root;password=;database=test;"
- Private connect As MySqlConnection
- Dim db As New DBManager
- Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
- db.testConnection()
- Try
- Me.connect = New MySqlConnection(connectionString)
- Me.connect.Open()
- Dim query As String = "SELECT * FROM table1"
- Dim datatable As New DataTable()
- Dim cmd As New MySqlCommand(query, Me.connect)
- Dim adapter As New MySqlDataAdapter(cmd)
- adapter.Fill(datatable)
- With Me.dgv_form1
- .DataSource = datatable
- .Columns(0).HeaderText = "ID"
- .Columns(1).HeaderText = "Firstname"
- .Columns(0).Width = 75
- .Columns(1).Width = 250
- End With
- Catch ex As Exception
- MsgBox(ex.Message, MsgBoxStyle.Critical, "Connection Failed")
- End Try
- End Sub
- Private Sub Button1_Click(sender As Object, e As EventArgs) Handles btn_add.Click
- Dim ob As New TestBean(50, "Davis luther")
- db.addUser(ob)
- db.testConnection()
- Try
- Me.connect = New MySqlConnection(connectionString)
- Me.connect.Open()
- Dim query As String = "SELECT * FROM table1"
- Dim datatable As New DataTable()
- Dim cmd As New MySqlCommand(query, Me.connect)
- Dim adapter As New MySqlDataAdapter(cmd)
- adapter.Fill(datatable)
- With Me.dgv_form1
- .DataSource = datatable
- .Columns(0).HeaderText = "ID"
- .Columns(1).HeaderText = "Firstname"
- .Columns(0).Width = 75
- .Columns(1).Width = 250
- End With
- Catch ex As Exception
- MsgBox(ex.Message, MsgBoxStyle.Critical, "Connection Failed")
- End Try
- End Sub
- Private Sub btn_edit_Click(sender As Object, e As EventArgs) Handles btn_edit.Click
- Dim ob As New TestBean(6, "Georges")
- db.editUser(ob)
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement