16,555
社区成员
发帖
与我相关
我的任务
分享
Public Function Run_Sqlstr(ByVal SqlStr As String) As Int64
Dim cn As New SqlConnection(My.Settings.CnStr)
cn.Open()
Using txn As SqlTransaction = cn.BeginTransaction("开始事务")
Try
Dim cmd As New SqlCommand(SqlStr, cn)
cmd.Transaction = txn
Dim ChRow As Integer = cmd.ExecuteNonQuery()
txn.Commit()
Return ChRow
Catch ex As Exception
txn.Rollback()
Throw New Exception(ex.Message.ToString)
Finally
cn.Close()
End Try
End Using
End Function
Private Sub Button登陆_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button登陆.Click
If UserBLL.CheckUserExist(TXT用户名.Text, TXT密码.Text) Then
Me.Close()
End If
End Sub
Public Function CheckUserExist(ByVal UserName As String, ByVal UserPassWord As String) As Boolean
If UserName.Trim.ToString = "" Or UserPassWord.Trim.ToString = "" Then
MsgBox("用户名及密码不能为空!")
Return False
Exit Function
End If
Dim TmpSqlStr As String = "SELECT count(*) FROM UserInfo where username ='" & UserName & "' and userpassword ='" & UserPassWord & "'"
If DAL.Run_Sqlstr(TmpSqlStr) = 1 Then
Return True
Else
MsgBox("用户名或密码错误!")
Return False
End If
End Function
Public Function Run_Sqlstr(ByVal SqlStr As String) As Int64
Dim cn As New SqlConnection(CnStr)
cn.Open()
Using txn As SqlTransaction = cn.BeginTransaction("开始事务")
Try
Dim cmd As New SqlCommand(SqlStr, cn)
cmd.Transaction = txn
Dim ChRow As Integer = cmd.ExecuteScalar
txn.Commit()
Return ChRow
Catch ex As Exception
txn.Rollback()
Throw New Exception(ex.Message.ToString)
Finally
cn.Close()
End Try
End Using
End Function