Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ember.js/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql Visual Basic数据库登录-代码将不起作用_Mysql_Asp.net_Sql Server_Vb.net_Visual Studio 2013 - Fatal编程技术网

Mysql Visual Basic数据库登录-代码将不起作用

Mysql Visual Basic数据库登录-代码将不起作用,mysql,asp.net,sql-server,vb.net,visual-studio-2013,Mysql,Asp.net,Sql Server,Vb.net,Visual Studio 2013,我已经有了数据库中用户的用户名和密码,我想从两个文本框中创建一个登录来连接到数据库,这是我到目前为止所拥有的,但它无法工作 Partial Class Pages_Login Inherits System.Web.UI.Page Protected Sub btnlogin_Click(sender As Object, e As EventArgs) Handles btnlogin.Click Dim patientNo As String Dim password As Str

我已经有了数据库中用户的用户名和密码,我想从两个文本框中创建一个登录来连接到数据库,这是我到目前为止所拥有的,但它无法工作

Partial Class Pages_Login


Inherits System.Web.UI.Page
Protected Sub btnlogin_Click(sender As Object, e As EventArgs) Handles   btnlogin.Click

Dim patientNo As String
Dim password As String
Dim bAuthethicated As Boolean
patientNo = txtuser.Text
password = txtpassword.Text
bAuthethicated = CheckUser(patientNo, password)

If bAuthethicated Then
    lblresult.Text() = "Student Number and Password are correct"

Else
    lblresult.Text() = "Incorrect Student Number and/or Password"


End If

End Sub

Dim cmdstring As String = "SELECT COUNT(*) FROM Patient  Where      Username=@STUDNO AND Password =@PASSWORD"

   conn As New SqlConnection("Data Source=.\SQLEXPRESS;
   AttachDbFilename=|DataDirectory|\surgery.mdf;IntegratedSecurity=True; UserInstance=True")

cmd= New SqlCommand(cmdstring, conn)
cmd.Parameters.Add("@PATIENTNO", SqlDbType.nchar).Value = patientNo
cmd.Parameters.Add("@PASSWORD", SqlDbType.nchar).Value = password
conn.Open()

found = CInt(cmd.ExecuteScalar)

End Using
Return (found > 0)
End Function

出现了一些构建错误

canyone能帮忙吗


亲切的问候那里有一两件事不对劲。。我认为这应该让你的代码编译没有任何错误

Partial Class Pages_Login
Inherits System.Web.UI.Page
Protected Sub btnlogin_Click(sender As Object, e As EventArgs) Handles btnlogin.Click

    Dim patientNo As String
    Dim password As String
    Dim bAuthethicated As Boolean
    patientNo = txtuser.Text
    password = txtpassword.Text
    bAuthethicated = CheckUser(patientNo, password)

    If bAuthethicated Then
        lblresult.Text() = "Student Number and Password are correct"

    Else
        lblresult.Text() = "Incorrect Student Number and/or Password"


    End If

End Sub
Public Function CheckUser(patientNo As String, password As String)
    Dim found As Boolean

    Dim cmdstring As String = "SELECT COUNT(*) FROM Patient  Where Username=@STUDNO AND Password =@PASSWORD"

    Dim conn As New SqlConnection("Data Source=.\SQLEXPRESS; AttachDbFilename=|DataDirectory|\surgery.mdf;IntegratedSecurity=True; UserInstance=True")

    Dim cmd = New SqlCommand(cmdstring, conn)
    cmd.Parameters.Add("@PATIENTNO", SqlDbType.NChar).Value = patientNo
    cmd.Parameters.Add("@PASSWORD", SqlDbType.NChar).Value = password
    conn.Open()

    found = CInt(cmd.ExecuteScalar)


    Return (found > 0)
End Function

End Class

那里出了一两件事。。我认为这应该让你的代码编译没有任何错误

Partial Class Pages_Login
Inherits System.Web.UI.Page
Protected Sub btnlogin_Click(sender As Object, e As EventArgs) Handles btnlogin.Click

    Dim patientNo As String
    Dim password As String
    Dim bAuthethicated As Boolean
    patientNo = txtuser.Text
    password = txtpassword.Text
    bAuthethicated = CheckUser(patientNo, password)

    If bAuthethicated Then
        lblresult.Text() = "Student Number and Password are correct"

    Else
        lblresult.Text() = "Incorrect Student Number and/or Password"


    End If

End Sub
Public Function CheckUser(patientNo As String, password As String)
    Dim found As Boolean

    Dim cmdstring As String = "SELECT COUNT(*) FROM Patient  Where Username=@STUDNO AND Password =@PASSWORD"

    Dim conn As New SqlConnection("Data Source=.\SQLEXPRESS; AttachDbFilename=|DataDirectory|\surgery.mdf;IntegratedSecurity=True; UserInstance=True")

    Dim cmd = New SqlCommand(cmdstring, conn)
    cmd.Parameters.Add("@PATIENTNO", SqlDbType.NChar).Value = patientNo
    cmd.Parameters.Add("@PASSWORD", SqlDbType.NChar).Value = password
    conn.Open()

    found = CInt(cmd.ExecuteScalar)


    Return (found > 0)
End Function

End Class