.net iam使用sql连接创建登录页时将发生bt错误{dr}无法转换值类型

.net iam使用sql连接创建登录页时将发生bt错误{dr}无法转换值类型,.net,sql,c#-4.0,.net,Sql,C# 4.0,导入System.Data.SqlClient 部分类登录 继承System.Web.UI.Page Dim con As SqlConnection Dim cmd As SqlCommand Shared dr As SqlDataReader 'Shared da As SqlDataAdapter Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click con = N

导入System.Data.SqlClient 部分类登录 继承System.Web.UI.Page

Dim con As SqlConnection
Dim cmd As SqlCommand
Shared dr As SqlDataReader
'Shared da As SqlDataAdapter

Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    con = New SqlConnection("Data source=USER-PC\SQLEXPRESS; Initial catalog= icare; Integrated security=True")
    cmd = New SqlCommand("select * from userlogin where UserName='" + TextBox1.Text + "' and Password='" + TextBox3.Text + "'", con)
    SqlDataReader(dr)
    con.Open()
    dr = cmd.ExecuteReader()

    If (dr.Read()) Then
        TextBox1.Text = dr("user Name").ToString
        TextBox2.Text = dr("Password").ToString
        'If (TextBox1.Text = TextBox1.Text And TextBox3.Text = TextBox2.Text) Then
        '    Response.Redirect("Defaulft.aspx")
    Else
        Response.Redirect("Home.master")
        lbl.Visible = True
        lbl.Text = "Invalid USERNAME & PASSWORD"
    End If
    'End If
End Sub
Dim con As SqlConnection
Dim cmd As SqlCommand
Shared dr As SqlDataReader
'Shared da As SqlDataAdapter

Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    con = New SqlConnection("Data source=USER-PC\SQLEXPRESS; Initial catalog= icare; Integrated security=True")
    cmd = New SqlCommand("select * from userlogin where UserName='" + TextBox1.Text + "' and Password='" + TextBox3.Text + "'", con)
    SqlDataReader(dr)
    con.Open()
    dr = cmd.ExecuteReader()

    If (dr.Read()) Then
        TextBox1.Text = dr("user Name").ToString
        TextBox2.Text = dr("Password").ToString
        'If (TextBox1.Text = TextBox1.Text And TextBox3.Text = TextBox2.Text) Then
        '    Response.Redirect("Defaulft.aspx")
    Else
        Response.Redirect("Home.master")
        lbl.Visible = True
        lbl.Text = "Invalid USERNAME & PASSWORD"
    End If
    'End If
End Sub
Dim con As SqlConnection
Dim cmd As SqlCommand
Shared dr As SqlDataReader
'Shared da As SqlDataAdapter

Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    con = New SqlConnection("Data source=USER-PC\SQLEXPRESS; Initial catalog= icare; Integrated security=True")
    cmd = New SqlCommand("select * from userlogin where UserName='" + TextBox1.Text + "' and Password='" + TextBox3.Text + "'", con)
    SqlDataReader(dr)
    con.Open()
    dr = cmd.ExecuteReader()

    If (dr.Read()) Then
        TextBox1.Text = dr("user Name").ToString
        TextBox2.Text = dr("Password").ToString
        'If (TextBox1.Text = TextBox1.Text And TextBox3.Text = TextBox2.Text) Then
        '    Response.Redirect("Defaulft.aspx")
    Else
        Response.Redirect("Home.master")
        lbl.Visible = True
        lbl.Text = "Invalid USERNAME & PASSWORD"
    End If
    'End If
End Sub
Dim con As SqlConnection
Dim cmd As SqlCommand
Shared dr As SqlDataReader
'Shared da As SqlDataAdapter

Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    con = New SqlConnection("Data source=USER-PC\SQLEXPRESS; Initial catalog= icare; Integrated security=True")
    cmd = New SqlCommand("select * from userlogin where UserName='" + TextBox1.Text + "' and Password='" + TextBox3.Text + "'", con)
    SqlDataReader(dr)
    con.Open()
    dr = cmd.ExecuteReader()

    If (dr.Read()) Then
        TextBox1.Text = dr("user Name").ToString
        TextBox2.Text = dr("Password").ToString
        'If (TextBox1.Text = TextBox1.Text And TextBox3.Text = TextBox2.Text) Then
        '    Response.Redirect("Defaulft.aspx")
    Else
        Response.Redirect("Home.master")
        lbl.Visible = True
        lbl.Text = "Invalid USERNAME & PASSWORD"
    End If
    'End If
End Sub
Dim con As SqlConnection
Dim cmd As SqlCommand
Shared dr As SqlDataReader
'Shared da As SqlDataAdapter

Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    con = New SqlConnection("Data source=USER-PC\SQLEXPRESS; Initial catalog= icare; Integrated security=True")
    cmd = New SqlCommand("select * from userlogin where UserName='" + TextBox1.Text + "' and Password='" + TextBox3.Text + "'", con)
    SqlDataReader(dr)
    con.Open()
    dr = cmd.ExecuteReader()

    If (dr.Read()) Then
        TextBox1.Text = dr("user Name").ToString
        TextBox2.Text = dr("Password").ToString
        'If (TextBox1.Text = TextBox1.Text And TextBox3.Text = TextBox2.Text) Then
        '    Response.Redirect("Defaulft.aspx")
    Else
        Response.Redirect("Home.master")
        lbl.Visible = True
        lbl.Text = "Invalid USERNAME & PASSWORD"
    End If
    'End If
End Sub
Dim con As SqlConnection
Dim cmd As SqlCommand
Shared dr As SqlDataReader
'Shared da As SqlDataAdapter

Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    con = New SqlConnection("Data source=USER-PC\SQLEXPRESS; Initial catalog= icare; Integrated security=True")
    cmd = New SqlCommand("select * from userlogin where UserName='" + TextBox1.Text + "' and Password='" + TextBox3.Text + "'", con)
    SqlDataReader(dr)
    con.Open()
    dr = cmd.ExecuteReader()

    If (dr.Read()) Then
        TextBox1.Text = dr("user Name").ToString
        TextBox2.Text = dr("Password").ToString
        'If (TextBox1.Text = TextBox1.Text And TextBox3.Text = TextBox2.Text) Then
        '    Response.Redirect("Defaulft.aspx")
    Else
        Response.Redirect("Home.master")
        lbl.Visible = True
        lbl.Text = "Invalid USERNAME & PASSWORD"
    End If
    'End If
End Sub
末级 导入System.Data.SqlClient 部分类登录 继承System.Web.UI.Page

Dim con As SqlConnection
Dim cmd As SqlCommand
Shared dr As SqlDataReader
'Shared da As SqlDataAdapter

Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    con = New SqlConnection("Data source=USER-PC\SQLEXPRESS; Initial catalog= icare; Integrated security=True")
    cmd = New SqlCommand("select * from userlogin where UserName='" + TextBox1.Text + "' and Password='" + TextBox3.Text + "'", con)
    SqlDataReader(dr)
    con.Open()
    dr = cmd.ExecuteReader()

    If (dr.Read()) Then
        TextBox1.Text = dr("user Name").ToString
        TextBox2.Text = dr("Password").ToString
        'If (TextBox1.Text = TextBox1.Text And TextBox3.Text = TextBox2.Text) Then
        '    Response.Redirect("Defaulft.aspx")
    Else
        Response.Redirect("Home.master")
        lbl.Visible = True
        lbl.Text = "Invalid USERNAME & PASSWORD"
    End If
    'End If
End Sub
Dim con As SqlConnection
Dim cmd As SqlCommand
Shared dr As SqlDataReader
'Shared da As SqlDataAdapter

Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    con = New SqlConnection("Data source=USER-PC\SQLEXPRESS; Initial catalog= icare; Integrated security=True")
    cmd = New SqlCommand("select * from userlogin where UserName='" + TextBox1.Text + "' and Password='" + TextBox3.Text + "'", con)
    SqlDataReader(dr)
    con.Open()
    dr = cmd.ExecuteReader()

    If (dr.Read()) Then
        TextBox1.Text = dr("user Name").ToString
        TextBox2.Text = dr("Password").ToString
        'If (TextBox1.Text = TextBox1.Text And TextBox3.Text = TextBox2.Text) Then
        '    Response.Redirect("Defaulft.aspx")
    Else
        Response.Redirect("Home.master")
        lbl.Visible = True
        lbl.Text = "Invalid USERNAME & PASSWORD"
    End If
    'End If
End Sub
Dim con As SqlConnection
Dim cmd As SqlCommand
Shared dr As SqlDataReader
'Shared da As SqlDataAdapter

Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    con = New SqlConnection("Data source=USER-PC\SQLEXPRESS; Initial catalog= icare; Integrated security=True")
    cmd = New SqlCommand("select * from userlogin where UserName='" + TextBox1.Text + "' and Password='" + TextBox3.Text + "'", con)
    SqlDataReader(dr)
    con.Open()
    dr = cmd.ExecuteReader()

    If (dr.Read()) Then
        TextBox1.Text = dr("user Name").ToString
        TextBox2.Text = dr("Password").ToString
        'If (TextBox1.Text = TextBox1.Text And TextBox3.Text = TextBox2.Text) Then
        '    Response.Redirect("Defaulft.aspx")
    Else
        Response.Redirect("Home.master")
        lbl.Visible = True
        lbl.Text = "Invalid USERNAME & PASSWORD"
    End If
    'End If
End Sub
Dim con As SqlConnection
Dim cmd As SqlCommand
Shared dr As SqlDataReader
'Shared da As SqlDataAdapter

Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    con = New SqlConnection("Data source=USER-PC\SQLEXPRESS; Initial catalog= icare; Integrated security=True")
    cmd = New SqlCommand("select * from userlogin where UserName='" + TextBox1.Text + "' and Password='" + TextBox3.Text + "'", con)
    SqlDataReader(dr)
    con.Open()
    dr = cmd.ExecuteReader()

    If (dr.Read()) Then
        TextBox1.Text = dr("user Name").ToString
        TextBox2.Text = dr("Password").ToString
        'If (TextBox1.Text = TextBox1.Text And TextBox3.Text = TextBox2.Text) Then
        '    Response.Redirect("Defaulft.aspx")
    Else
        Response.Redirect("Home.master")
        lbl.Visible = True
        lbl.Text = "Invalid USERNAME & PASSWORD"
    End If
    'End If
End Sub
Dim con As SqlConnection
Dim cmd As SqlCommand
Shared dr As SqlDataReader
'Shared da As SqlDataAdapter

Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    con = New SqlConnection("Data source=USER-PC\SQLEXPRESS; Initial catalog= icare; Integrated security=True")
    cmd = New SqlCommand("select * from userlogin where UserName='" + TextBox1.Text + "' and Password='" + TextBox3.Text + "'", con)
    SqlDataReader(dr)
    con.Open()
    dr = cmd.ExecuteReader()

    If (dr.Read()) Then
        TextBox1.Text = dr("user Name").ToString
        TextBox2.Text = dr("Password").ToString
        'If (TextBox1.Text = TextBox1.Text And TextBox3.Text = TextBox2.Text) Then
        '    Response.Redirect("Defaulft.aspx")
    Else
        Response.Redirect("Home.master")
        lbl.Visible = True
        lbl.Text = "Invalid USERNAME & PASSWORD"
    End If
    'End If
End Sub
Dim con As SqlConnection
Dim cmd As SqlCommand
Shared dr As SqlDataReader
'Shared da As SqlDataAdapter

Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    con = New SqlConnection("Data source=USER-PC\SQLEXPRESS; Initial catalog= icare; Integrated security=True")
    cmd = New SqlCommand("select * from userlogin where UserName='" + TextBox1.Text + "' and Password='" + TextBox3.Text + "'", con)
    SqlDataReader(dr)
    con.Open()
    dr = cmd.ExecuteReader()

    If (dr.Read()) Then
        TextBox1.Text = dr("user Name").ToString
        TextBox2.Text = dr("Password").ToString
        'If (TextBox1.Text = TextBox1.Text And TextBox3.Text = TextBox2.Text) Then
        '    Response.Redirect("Defaulft.aspx")
    Else
        Response.Redirect("Home.master")
        lbl.Visible = True
        lbl.Text = "Invalid USERNAME & PASSWORD"
    End If
    'End If
End Sub
末级 导入System.Data.SqlClient 部分类登录 继承System.Web.UI.Page

Dim con As SqlConnection
Dim cmd As SqlCommand
Shared dr As SqlDataReader
'Shared da As SqlDataAdapter

Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    con = New SqlConnection("Data source=USER-PC\SQLEXPRESS; Initial catalog= icare; Integrated security=True")
    cmd = New SqlCommand("select * from userlogin where UserName='" + TextBox1.Text + "' and Password='" + TextBox3.Text + "'", con)
    SqlDataReader(dr)
    con.Open()
    dr = cmd.ExecuteReader()

    If (dr.Read()) Then
        TextBox1.Text = dr("user Name").ToString
        TextBox2.Text = dr("Password").ToString
        'If (TextBox1.Text = TextBox1.Text And TextBox3.Text = TextBox2.Text) Then
        '    Response.Redirect("Defaulft.aspx")
    Else
        Response.Redirect("Home.master")
        lbl.Visible = True
        lbl.Text = "Invalid USERNAME & PASSWORD"
    End If
    'End If
End Sub
Dim con As SqlConnection
Dim cmd As SqlCommand
Shared dr As SqlDataReader
'Shared da As SqlDataAdapter

Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    con = New SqlConnection("Data source=USER-PC\SQLEXPRESS; Initial catalog= icare; Integrated security=True")
    cmd = New SqlCommand("select * from userlogin where UserName='" + TextBox1.Text + "' and Password='" + TextBox3.Text + "'", con)
    SqlDataReader(dr)
    con.Open()
    dr = cmd.ExecuteReader()

    If (dr.Read()) Then
        TextBox1.Text = dr("user Name").ToString
        TextBox2.Text = dr("Password").ToString
        'If (TextBox1.Text = TextBox1.Text And TextBox3.Text = TextBox2.Text) Then
        '    Response.Redirect("Defaulft.aspx")
    Else
        Response.Redirect("Home.master")
        lbl.Visible = True
        lbl.Text = "Invalid USERNAME & PASSWORD"
    End If
    'End If
End Sub
Dim con As SqlConnection
Dim cmd As SqlCommand
Shared dr As SqlDataReader
'Shared da As SqlDataAdapter

Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    con = New SqlConnection("Data source=USER-PC\SQLEXPRESS; Initial catalog= icare; Integrated security=True")
    cmd = New SqlCommand("select * from userlogin where UserName='" + TextBox1.Text + "' and Password='" + TextBox3.Text + "'", con)
    SqlDataReader(dr)
    con.Open()
    dr = cmd.ExecuteReader()

    If (dr.Read()) Then
        TextBox1.Text = dr("user Name").ToString
        TextBox2.Text = dr("Password").ToString
        'If (TextBox1.Text = TextBox1.Text And TextBox3.Text = TextBox2.Text) Then
        '    Response.Redirect("Defaulft.aspx")
    Else
        Response.Redirect("Home.master")
        lbl.Visible = True
        lbl.Text = "Invalid USERNAME & PASSWORD"
    End If
    'End If
End Sub
Dim con As SqlConnection
Dim cmd As SqlCommand
Shared dr As SqlDataReader
'Shared da As SqlDataAdapter

Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    con = New SqlConnection("Data source=USER-PC\SQLEXPRESS; Initial catalog= icare; Integrated security=True")
    cmd = New SqlCommand("select * from userlogin where UserName='" + TextBox1.Text + "' and Password='" + TextBox3.Text + "'", con)
    SqlDataReader(dr)
    con.Open()
    dr = cmd.ExecuteReader()

    If (dr.Read()) Then
        TextBox1.Text = dr("user Name").ToString
        TextBox2.Text = dr("Password").ToString
        'If (TextBox1.Text = TextBox1.Text And TextBox3.Text = TextBox2.Text) Then
        '    Response.Redirect("Defaulft.aspx")
    Else
        Response.Redirect("Home.master")
        lbl.Visible = True
        lbl.Text = "Invalid USERNAME & PASSWORD"
    End If
    'End If
End Sub
Dim con As SqlConnection
Dim cmd As SqlCommand
Shared dr As SqlDataReader
'Shared da As SqlDataAdapter

Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    con = New SqlConnection("Data source=USER-PC\SQLEXPRESS; Initial catalog= icare; Integrated security=True")
    cmd = New SqlCommand("select * from userlogin where UserName='" + TextBox1.Text + "' and Password='" + TextBox3.Text + "'", con)
    SqlDataReader(dr)
    con.Open()
    dr = cmd.ExecuteReader()

    If (dr.Read()) Then
        TextBox1.Text = dr("user Name").ToString
        TextBox2.Text = dr("Password").ToString
        'If (TextBox1.Text = TextBox1.Text And TextBox3.Text = TextBox2.Text) Then
        '    Response.Redirect("Defaulft.aspx")
    Else
        Response.Redirect("Home.master")
        lbl.Visible = True
        lbl.Text = "Invalid USERNAME & PASSWORD"
    End If
    'End If
End Sub
Dim con As SqlConnection
Dim cmd As SqlCommand
Shared dr As SqlDataReader
'Shared da As SqlDataAdapter

Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    con = New SqlConnection("Data source=USER-PC\SQLEXPRESS; Initial catalog= icare; Integrated security=True")
    cmd = New SqlCommand("select * from userlogin where UserName='" + TextBox1.Text + "' and Password='" + TextBox3.Text + "'", con)
    SqlDataReader(dr)
    con.Open()
    dr = cmd.ExecuteReader()

    If (dr.Read()) Then
        TextBox1.Text = dr("user Name").ToString
        TextBox2.Text = dr("Password").ToString
        'If (TextBox1.Text = TextBox1.Text And TextBox3.Text = TextBox2.Text) Then
        '    Response.Redirect("Defaulft.aspx")
    Else
        Response.Redirect("Home.master")
        lbl.Visible = True
        lbl.Text = "Invalid USERNAME & PASSWORD"
    End If
    'End If
End Sub
末级 导入System.Data.SqlClient 部分类登录 继承System.Web.UI.Page

Dim con As SqlConnection
Dim cmd As SqlCommand
Shared dr As SqlDataReader
'Shared da As SqlDataAdapter

Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    con = New SqlConnection("Data source=USER-PC\SQLEXPRESS; Initial catalog= icare; Integrated security=True")
    cmd = New SqlCommand("select * from userlogin where UserName='" + TextBox1.Text + "' and Password='" + TextBox3.Text + "'", con)
    SqlDataReader(dr)
    con.Open()
    dr = cmd.ExecuteReader()

    If (dr.Read()) Then
        TextBox1.Text = dr("user Name").ToString
        TextBox2.Text = dr("Password").ToString
        'If (TextBox1.Text = TextBox1.Text And TextBox3.Text = TextBox2.Text) Then
        '    Response.Redirect("Defaulft.aspx")
    Else
        Response.Redirect("Home.master")
        lbl.Visible = True
        lbl.Text = "Invalid USERNAME & PASSWORD"
    End If
    'End If
End Sub
Dim con As SqlConnection
Dim cmd As SqlCommand
Shared dr As SqlDataReader
'Shared da As SqlDataAdapter

Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    con = New SqlConnection("Data source=USER-PC\SQLEXPRESS; Initial catalog= icare; Integrated security=True")
    cmd = New SqlCommand("select * from userlogin where UserName='" + TextBox1.Text + "' and Password='" + TextBox3.Text + "'", con)
    SqlDataReader(dr)
    con.Open()
    dr = cmd.ExecuteReader()

    If (dr.Read()) Then
        TextBox1.Text = dr("user Name").ToString
        TextBox2.Text = dr("Password").ToString
        'If (TextBox1.Text = TextBox1.Text And TextBox3.Text = TextBox2.Text) Then
        '    Response.Redirect("Defaulft.aspx")
    Else
        Response.Redirect("Home.master")
        lbl.Visible = True
        lbl.Text = "Invalid USERNAME & PASSWORD"
    End If
    'End If
End Sub
Dim con As SqlConnection
Dim cmd As SqlCommand
Shared dr As SqlDataReader
'Shared da As SqlDataAdapter

Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    con = New SqlConnection("Data source=USER-PC\SQLEXPRESS; Initial catalog= icare; Integrated security=True")
    cmd = New SqlCommand("select * from userlogin where UserName='" + TextBox1.Text + "' and Password='" + TextBox3.Text + "'", con)
    SqlDataReader(dr)
    con.Open()
    dr = cmd.ExecuteReader()

    If (dr.Read()) Then
        TextBox1.Text = dr("user Name").ToString
        TextBox2.Text = dr("Password").ToString
        'If (TextBox1.Text = TextBox1.Text And TextBox3.Text = TextBox2.Text) Then
        '    Response.Redirect("Defaulft.aspx")
    Else
        Response.Redirect("Home.master")
        lbl.Visible = True
        lbl.Text = "Invalid USERNAME & PASSWORD"
    End If
    'End If
End Sub
Dim con As SqlConnection
Dim cmd As SqlCommand
Shared dr As SqlDataReader
'Shared da As SqlDataAdapter

Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    con = New SqlConnection("Data source=USER-PC\SQLEXPRESS; Initial catalog= icare; Integrated security=True")
    cmd = New SqlCommand("select * from userlogin where UserName='" + TextBox1.Text + "' and Password='" + TextBox3.Text + "'", con)
    SqlDataReader(dr)
    con.Open()
    dr = cmd.ExecuteReader()

    If (dr.Read()) Then
        TextBox1.Text = dr("user Name").ToString
        TextBox2.Text = dr("Password").ToString
        'If (TextBox1.Text = TextBox1.Text And TextBox3.Text = TextBox2.Text) Then
        '    Response.Redirect("Defaulft.aspx")
    Else
        Response.Redirect("Home.master")
        lbl.Visible = True
        lbl.Text = "Invalid USERNAME & PASSWORD"
    End If
    'End If
End Sub
Dim con As SqlConnection
Dim cmd As SqlCommand
Shared dr As SqlDataReader
'Shared da As SqlDataAdapter

Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    con = New SqlConnection("Data source=USER-PC\SQLEXPRESS; Initial catalog= icare; Integrated security=True")
    cmd = New SqlCommand("select * from userlogin where UserName='" + TextBox1.Text + "' and Password='" + TextBox3.Text + "'", con)
    SqlDataReader(dr)
    con.Open()
    dr = cmd.ExecuteReader()

    If (dr.Read()) Then
        TextBox1.Text = dr("user Name").ToString
        TextBox2.Text = dr("Password").ToString
        'If (TextBox1.Text = TextBox1.Text And TextBox3.Text = TextBox2.Text) Then
        '    Response.Redirect("Defaulft.aspx")
    Else
        Response.Redirect("Home.master")
        lbl.Visible = True
        lbl.Text = "Invalid USERNAME & PASSWORD"
    End If
    'End If
End Sub
Dim con As SqlConnection
Dim cmd As SqlCommand
Shared dr As SqlDataReader
'Shared da As SqlDataAdapter

Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    con = New SqlConnection("Data source=USER-PC\SQLEXPRESS; Initial catalog= icare; Integrated security=True")
    cmd = New SqlCommand("select * from userlogin where UserName='" + TextBox1.Text + "' and Password='" + TextBox3.Text + "'", con)
    SqlDataReader(dr)
    con.Open()
    dr = cmd.ExecuteReader()

    If (dr.Read()) Then
        TextBox1.Text = dr("user Name").ToString
        TextBox2.Text = dr("Password").ToString
        'If (TextBox1.Text = TextBox1.Text And TextBox3.Text = TextBox2.Text) Then
        '    Response.Redirect("Defaulft.aspx")
    Else
        Response.Redirect("Home.master")
        lbl.Visible = True
        lbl.Text = "Invalid USERNAME & PASSWORD"
    End If
    'End If
End Sub
末级 导入System.Data.SqlClient 部分类登录 继承System.Web.UI.Page

Dim con As SqlConnection
Dim cmd As SqlCommand
Shared dr As SqlDataReader
'Shared da As SqlDataAdapter

Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    con = New SqlConnection("Data source=USER-PC\SQLEXPRESS; Initial catalog= icare; Integrated security=True")
    cmd = New SqlCommand("select * from userlogin where UserName='" + TextBox1.Text + "' and Password='" + TextBox3.Text + "'", con)
    SqlDataReader(dr)
    con.Open()
    dr = cmd.ExecuteReader()

    If (dr.Read()) Then
        TextBox1.Text = dr("user Name").ToString
        TextBox2.Text = dr("Password").ToString
        'If (TextBox1.Text = TextBox1.Text And TextBox3.Text = TextBox2.Text) Then
        '    Response.Redirect("Defaulft.aspx")
    Else
        Response.Redirect("Home.master")
        lbl.Visible = True
        lbl.Text = "Invalid USERNAME & PASSWORD"
    End If
    'End If
End Sub
Dim con As SqlConnection
Dim cmd As SqlCommand
Shared dr As SqlDataReader
'Shared da As SqlDataAdapter

Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    con = New SqlConnection("Data source=USER-PC\SQLEXPRESS; Initial catalog= icare; Integrated security=True")
    cmd = New SqlCommand("select * from userlogin where UserName='" + TextBox1.Text + "' and Password='" + TextBox3.Text + "'", con)
    SqlDataReader(dr)
    con.Open()
    dr = cmd.ExecuteReader()

    If (dr.Read()) Then
        TextBox1.Text = dr("user Name").ToString
        TextBox2.Text = dr("Password").ToString
        'If (TextBox1.Text = TextBox1.Text And TextBox3.Text = TextBox2.Text) Then
        '    Response.Redirect("Defaulft.aspx")
    Else
        Response.Redirect("Home.master")
        lbl.Visible = True
        lbl.Text = "Invalid USERNAME & PASSWORD"
    End If
    'End If
End Sub
Dim con As SqlConnection
Dim cmd As SqlCommand
Shared dr As SqlDataReader
'Shared da As SqlDataAdapter

Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    con = New SqlConnection("Data source=USER-PC\SQLEXPRESS; Initial catalog= icare; Integrated security=True")
    cmd = New SqlCommand("select * from userlogin where UserName='" + TextBox1.Text + "' and Password='" + TextBox3.Text + "'", con)
    SqlDataReader(dr)
    con.Open()
    dr = cmd.ExecuteReader()

    If (dr.Read()) Then
        TextBox1.Text = dr("user Name").ToString
        TextBox2.Text = dr("Password").ToString
        'If (TextBox1.Text = TextBox1.Text And TextBox3.Text = TextBox2.Text) Then
        '    Response.Redirect("Defaulft.aspx")
    Else
        Response.Redirect("Home.master")
        lbl.Visible = True
        lbl.Text = "Invalid USERNAME & PASSWORD"
    End If
    'End If
End Sub
Dim con As SqlConnection
Dim cmd As SqlCommand
Shared dr As SqlDataReader
'Shared da As SqlDataAdapter

Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    con = New SqlConnection("Data source=USER-PC\SQLEXPRESS; Initial catalog= icare; Integrated security=True")
    cmd = New SqlCommand("select * from userlogin where UserName='" + TextBox1.Text + "' and Password='" + TextBox3.Text + "'", con)
    SqlDataReader(dr)
    con.Open()
    dr = cmd.ExecuteReader()

    If (dr.Read()) Then
        TextBox1.Text = dr("user Name").ToString
        TextBox2.Text = dr("Password").ToString
        'If (TextBox1.Text = TextBox1.Text And TextBox3.Text = TextBox2.Text) Then
        '    Response.Redirect("Defaulft.aspx")
    Else
        Response.Redirect("Home.master")
        lbl.Visible = True
        lbl.Text = "Invalid USERNAME & PASSWORD"
    End If
    'End If
End Sub
Dim con As SqlConnection
Dim cmd As SqlCommand
Shared dr As SqlDataReader
'Shared da As SqlDataAdapter

Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    con = New SqlConnection("Data source=USER-PC\SQLEXPRESS; Initial catalog= icare; Integrated security=True")
    cmd = New SqlCommand("select * from userlogin where UserName='" + TextBox1.Text + "' and Password='" + TextBox3.Text + "'", con)
    SqlDataReader(dr)
    con.Open()
    dr = cmd.ExecuteReader()

    If (dr.Read()) Then
        TextBox1.Text = dr("user Name").ToString
        TextBox2.Text = dr("Password").ToString
        'If (TextBox1.Text = TextBox1.Text And TextBox3.Text = TextBox2.Text) Then
        '    Response.Redirect("Defaulft.aspx")
    Else
        Response.Redirect("Home.master")
        lbl.Visible = True
        lbl.Text = "Invalid USERNAME & PASSWORD"
    End If
    'End If
End Sub
Dim con As SqlConnection
Dim cmd As SqlCommand
Shared dr As SqlDataReader
'Shared da As SqlDataAdapter

Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    con = New SqlConnection("Data source=USER-PC\SQLEXPRESS; Initial catalog= icare; Integrated security=True")
    cmd = New SqlCommand("select * from userlogin where UserName='" + TextBox1.Text + "' and Password='" + TextBox3.Text + "'", con)
    SqlDataReader(dr)
    con.Open()
    dr = cmd.ExecuteReader()

    If (dr.Read()) Then
        TextBox1.Text = dr("user Name").ToString
        TextBox2.Text = dr("Password").ToString
        'If (TextBox1.Text = TextBox1.Text And TextBox3.Text = TextBox2.Text) Then
        '    Response.Redirect("Defaulft.aspx")
    Else
        Response.Redirect("Home.master")
        lbl.Visible = True
        lbl.Text = "Invalid USERNAME & PASSWORD"
    End If
    'End If
End Sub
末级 导入System.Data.SqlClient 部分类登录 继承System.Web.UI.Page

Dim con As SqlConnection
Dim cmd As SqlCommand
Shared dr As SqlDataReader
'Shared da As SqlDataAdapter

Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    con = New SqlConnection("Data source=USER-PC\SQLEXPRESS; Initial catalog= icare; Integrated security=True")
    cmd = New SqlCommand("select * from userlogin where UserName='" + TextBox1.Text + "' and Password='" + TextBox3.Text + "'", con)
    SqlDataReader(dr)
    con.Open()
    dr = cmd.ExecuteReader()

    If (dr.Read()) Then
        TextBox1.Text = dr("user Name").ToString
        TextBox2.Text = dr("Password").ToString
        'If (TextBox1.Text = TextBox1.Text And TextBox3.Text = TextBox2.Text) Then
        '    Response.Redirect("Defaulft.aspx")
    Else
        Response.Redirect("Home.master")
        lbl.Visible = True
        lbl.Text = "Invalid USERNAME & PASSWORD"
    End If
    'End If
End Sub
Dim con As SqlConnection
Dim cmd As SqlCommand
Shared dr As SqlDataReader
'Shared da As SqlDataAdapter

Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    con = New SqlConnection("Data source=USER-PC\SQLEXPRESS; Initial catalog= icare; Integrated security=True")
    cmd = New SqlCommand("select * from userlogin where UserName='" + TextBox1.Text + "' and Password='" + TextBox3.Text + "'", con)
    SqlDataReader(dr)
    con.Open()
    dr = cmd.ExecuteReader()

    If (dr.Read()) Then
        TextBox1.Text = dr("user Name").ToString
        TextBox2.Text = dr("Password").ToString
        'If (TextBox1.Text = TextBox1.Text And TextBox3.Text = TextBox2.Text) Then
        '    Response.Redirect("Defaulft.aspx")
    Else
        Response.Redirect("Home.master")
        lbl.Visible = True
        lbl.Text = "Invalid USERNAME & PASSWORD"
    End If
    'End If
End Sub
Dim con As SqlConnection
Dim cmd As SqlCommand
Shared dr As SqlDataReader
'Shared da As SqlDataAdapter

Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    con = New SqlConnection("Data source=USER-PC\SQLEXPRESS; Initial catalog= icare; Integrated security=True")
    cmd = New SqlCommand("select * from userlogin where UserName='" + TextBox1.Text + "' and Password='" + TextBox3.Text + "'", con)
    SqlDataReader(dr)
    con.Open()
    dr = cmd.ExecuteReader()

    If (dr.Read()) Then
        TextBox1.Text = dr("user Name").ToString
        TextBox2.Text = dr("Password").ToString
        'If (TextBox1.Text = TextBox1.Text And TextBox3.Text = TextBox2.Text) Then
        '    Response.Redirect("Defaulft.aspx")
    Else
        Response.Redirect("Home.master")
        lbl.Visible = True
        lbl.Text = "Invalid USERNAME & PASSWORD"
    End If
    'End If
End Sub
Dim con As SqlConnection
Dim cmd As SqlCommand
Shared dr As SqlDataReader
'Shared da As SqlDataAdapter

Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    con = New SqlConnection("Data source=USER-PC\SQLEXPRESS; Initial catalog= icare; Integrated security=True")
    cmd = New SqlCommand("select * from userlogin where UserName='" + TextBox1.Text + "' and Password='" + TextBox3.Text + "'", con)
    SqlDataReader(dr)
    con.Open()
    dr = cmd.ExecuteReader()

    If (dr.Read()) Then
        TextBox1.Text = dr("user Name").ToString
        TextBox2.Text = dr("Password").ToString
        'If (TextBox1.Text = TextBox1.Text And TextBox3.Text = TextBox2.Text) Then
        '    Response.Redirect("Defaulft.aspx")
    Else
        Response.Redirect("Home.master")
        lbl.Visible = True
        lbl.Text = "Invalid USERNAME & PASSWORD"
    End If
    'End If
End Sub
Dim con As SqlConnection
Dim cmd As SqlCommand
Shared dr As SqlDataReader
'Shared da As SqlDataAdapter

Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    con = New SqlConnection("Data source=USER-PC\SQLEXPRESS; Initial catalog= icare; Integrated security=True")
    cmd = New SqlCommand("select * from userlogin where UserName='" + TextBox1.Text + "' and Password='" + TextBox3.Text + "'", con)
    SqlDataReader(dr)
    con.Open()
    dr = cmd.ExecuteReader()

    If (dr.Read()) Then
        TextBox1.Text = dr("user Name").ToString
        TextBox2.Text = dr("Password").ToString
        'If (TextBox1.Text = TextBox1.Text And TextBox3.Text = TextBox2.Text) Then
        '    Response.Redirect("Defaulft.aspx")
    Else
        Response.Redirect("Home.master")
        lbl.Visible = True
        lbl.Text = "Invalid USERNAME & PASSWORD"
    End If
    'End If
End Sub
Dim con As SqlConnection
Dim cmd As SqlCommand
Shared dr As SqlDataReader
'Shared da As SqlDataAdapter

Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    con = New SqlConnection("Data source=USER-PC\SQLEXPRESS; Initial catalog= icare; Integrated security=True")
    cmd = New SqlCommand("select * from userlogin where UserName='" + TextBox1.Text + "' and Password='" + TextBox3.Text + "'", con)
    SqlDataReader(dr)
    con.Open()
    dr = cmd.ExecuteReader()

    If (dr.Read()) Then
        TextBox1.Text = dr("user Name").ToString
        TextBox2.Text = dr("Password").ToString
        'If (TextBox1.Text = TextBox1.Text And TextBox3.Text = TextBox2.Text) Then
        '    Response.Redirect("Defaulft.aspx")
    Else
        Response.Redirect("Home.master")
        lbl.Visible = True
        lbl.Text = "Invalid USERNAME & PASSWORD"
    End If
    'End If
End Sub

End Class

您的代码似乎不完整(可能被截断?)-无论如何,我建议您执行逐步跟踪(F5)。如果可以连接到数据库,请确定有问题的语句。从你的姿势看不清楚哪条线失败了

您的代码:

SqlDataReader(dr)

对我来说是模棱两可的

检查:查看与您的案例类似的清晰示例