module1.vb

来自「The Management Information System of Lib」· VB 代码 · 共 46 行

VB
46
字号
Imports System.Data.SqlClient
Module Module1
    Public cnstr As String
    Public Sub ShowMsg(ByVal msg As String)
        MessageBox.Show(msg, "success", MessageBoxButtons.OK, MessageBoxIcon.Information)
    End Sub

    Public Function validateLogin(ByVal uid As String, ByVal pwd As String) As Boolean
        Dim IsCorrect As Boolean = False
        Dim cnmy As New SqlConnection(cnstr)
        Dim cmd As New SqlCommand

        With cmd
            .Connection = cnmy
            .CommandType = CommandType.Text
            .CommandText = "select count(*) from manager where Man_id=@Man_id and Man_pwd=@Man_pwd"
        End With

        Dim mMan_id As New SqlParameter("@Man_id", SqlDbType.NVarChar, 50)
        Dim mMan_pwd As New SqlParameter("@Man_pwd", SqlDbType.NVarChar, 12)
        With cmd.Parameters
            .Add(mMan_id)
            .Add(mMan_pwd)
        End With
        mMan_id.Value = uid
        mMan_pwd.Value = pwd

        Try
            cnmy.Open()
            If cmd.ExecuteScalar = 1 Then
                IsCorrect = True
            End If
        Catch ex As Exception
            MessageBox.Show("登陆验证时数据库发生错误" + vbCrLf + ex.Message, _
            "error", MessageBoxButtons.OK, MessageBoxIcon.Stop)
            Return False
        Finally
            cnmy.Close()
            If Not cnmy Is Nothing Then
                cnmy.Dispose()
            End If
        End Try
        Return IsCorrect
    End Function
End Module

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?