-4

导入 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

结束类导入 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

结束类导入 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

结束类导入 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

结束类导入 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

结束类导入 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

结束类

4

1 回答 1

0

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

你的代码:

SqlDataReader(博士)

对我来说模棱两可。

检查:MSDN-Retrieving Data Using a DataReader以获得与您的案例类似的清晰示例。

于 2013-09-16T06:15:55.143 回答