Đang chuẩn bị liên kết để tải về tài liệu:
Lớp kết nối

Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ

Lớp kết nối Imports System.Data.SqlClient 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 System.Data.SqlClient 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 SqlClient.SqlConnection(strconn) Try myconn.open() Catch ex As Exception strerror = MsgBox(ex.Message) 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 SqlClient.SqlConnection(strconn) Try myconn.open() Catch ex As Exception strerror = MsgBox(ex.Message) End Try Return strerror End Function End Class Nút kết nối Public Class Form1 Private Sub lblmatkhau_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblmatkhau.Click End Sub Private Sub cboloaiketnoi_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboloaiketnoi.SelectedIndexChanged txtnguoidung.Enabled = False txtmatkhau.Enabled = False If cboloaiketnoi.Text = "SQL Server Authentication" Then txtnguoidung.Enabled = True txtmatkhau.Enabled = True End If End Sub Private Sub btnketnoi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnketnoi.Click Dim kn As New ketnoi Dim thongbao As String = "" If (cboloaiketnoi.Text = "Windown Authentication") Then thongbao = kn.ketnoi2(txtmaychu.Text, txtcsdl.Text) Else thongbao = kn.ketnoi(txtmaychu.Text, txtcsdl.Text, txtnguoidung.Text, txtmatkhau.Text) End If If thongbao = "" Then MsgBox("Đã kết nối thành công", MsgBoxStyle.Information) txtmaychu.Focus() Else MsgBox(thongbao, MsgBoxStyle.Critical) End If End Sub End Class