Lớp kết nối Imports Public Class ketnoi Public Function ketnoi(ByVal maychu As String, ByVal csdl As String, ByVal nguoidung As String, ByVal matkhau As String) As String Dim strconn As String Dim strerror As String = "" | Lớp kết nối Imports Public Class ketnoi Public Function ketnoi(ByVal maychu As String, ByVal csdl As String, ByVal nguoidung As String, ByVal matkhau As String) As String Dim strconn As String Dim strerror As String = "" strconn = "Server = '" & maychu & "';Database = '" & csdl & "';uid = '" & nguoidung & "';Pwd = '" & matkhau & "'" Dim myconn = New (strconn) Try () Catch ex As Exception strerror = MsgBox() End Try Return strerror End Function Public Function ketnoi2(ByVal maychu As String, ByVal csdl As String) As String Dim strconn As String Dim strerror As String = "" strconn = "server = '" & maychu & "';Database = '" & csdl & "';integated security = sspi" Dim myconn = New (strconn) Try () Catch ex As Exception strerror = MsgBox() End Try Return strerror End Function End Class Nút kết nối Public Class Form1 Private Sub lblmatkhau_Click(ByVal sender As , ByVal e As ) Handles End Sub Private Sub cboloaiketnoi_SelectedIndexChanged(ByVal sender As , ByVal e As ) Handles = False = False If = "SQL Server Authentication" Then = True = True End If End Sub Private Sub btnketnoi_Click(ByVal sender As , ByVal e As ) Handles Dim kn As New ketnoi Dim thongbao As String = "" If ( = "Windown Authentication") Then thongbao = (, ) Else thongbao = (, , , ) End If If thongbao = "" Then MsgBox("Đã kết nối thành công", ) () Else MsgBox(thongbao, ) End If End Sub End Class