写了登陆的简单代码,用ACCESS数据库,以前没有用过,用的是SQL SERVER
  但现在有个问题总报错,请高手指点其中    Dim dr As OleDbDataReader = cmd.ExecuteReader这句系统提示 异常,碉用了另外一个函数。请问着是什么情况Imports System.Data
Imports System.Data.OleDbPartial Class _Default
    Inherits System.Web.UI.Page    Private Sub page_load(ByVal sender As System.Object, ByVal e As EventArgs)
       
    End Sub    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click        Dim con As New OleDbConnection
        con.ConnectionString = "provider = Microsoft.Jet.OLEDB.4.0;DATA Source=" & Server.MapPath("tzdatabase.mdb")
        con.Open()        Dim str As String = "select * from login where user=" + TextBox1.Text + " and " + TextBox2.Text + ""
        Dim cmd As New OleDbCommand(str, con)
        Dim dr As OleDbDataReader = cmd.ExecuteReader
       If dr.Read Then
            Response.Redirect("cg.aspx")
        Else
            Response.Write("<script languge='javascript'> alert('登录失败');window.top.location.href='Default.aspx';</script>;return")        End If    End Sub    Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
        TextBox1.Text = ""
        TextBox2.Text = ""    End Sub    Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButton1.Click
        Response.Redirect("rigester.aspx")    End Sub
End Class

解决方案 »

  1.   

    Dim str As String = "select * from login where user=" + TextBox1.Text + " and " + TextBox2.Text + ""
    是不是少了where password=
      

  2.   

    这样的异常一般情况下是SQL语句问题!因为SQL server的数据类型是不同的!
    把SQL语句改为:
    Dim str As String = "select * from login where user='" + TextBox1.Text + "' and password='" + TextBox2.Text + "'" 试下
    user,password字段为文本类型
      

  3.   

    这样的异常一般情况下是SQL语句问题!因为SQL server的数据类型和Access的数据类型是不同的把SQL语句改为:
    Dim str As String = "select * from login where user='" + TextBox1.Text + "' and password='" + TextBox2.Text + "'" 试下
    Access的数据中user,password字段为文本类型