Advertisement
hungvb

VB.NET Connecting

Dec 12th, 2021
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 0.90 KB | None | 0 0
  1. Imports MySql.Data.MySqlClient
  2. Public Class Form1
  3.     Dim ketnoi As New MySqlConnection("datasource=localhost;port=3306;username=root;password=")
  4.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  5.  
  6.     End Sub
  7.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  8.         Try
  9.             '   connection.Open()
  10.             ketnoi.Open()
  11.             Label1.Text = "connected"
  12.  
  13.         Catch ex As Exception
  14.             MessageBox.Show(ex.ToString())
  15.         End Try
  16.     End Sub
  17.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  18.         Try
  19.             ketnoi.Close()
  20.             Label1.Text = "not connected"
  21.         Catch ex As Exception
  22.             MessageBox.Show(ex.ToString())
  23.         End Try
  24.     End Sub
  25. End Class
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement