SqlDataReader Reader = SqlCommand1..ExecuteReader()
if(Reader.Read()){
//执行你的代码
}

解决方案 »

  1.   

    全给你:
    SqlConnection Myconn=new SqlConnection(StringDatabase);
    Myconn.Open();
    string StrDB="select * from  users  where username='"+TextBox1.Text+"' and Password='"+TextBox2.Text+"'"; 
    SqlCommand Mycomm=new  SqlCommand(StrDB,Myconn);
    SqlDataReader GetValue=null;
    GetValue=Mycomm.ExecuteReader();
    if(GetValue.Read())

    GenSessionID  GetID=new GenSessionID();
    //调用构造函数获得id
    string    GetSessionID= GetID.sessionid;
    Session["ID"]=GetSessionID;
    Response.Redirect ("Menu.aspx");
    }
    GetValue.Close();
    Myconn.Close ()
      

  2.   

    我是用VB做ASP。NET 我按照你们给我提供的方法但是?我声明它Dim Reader As SqlDataReader但是编译器不认识 SqlDataReader  这是为什么?
      

  3.   

    import System.Data.SqlClient
    就会有SqlDataReader了
      

  4.   

    我是用VB。NET 做网站,imports system.data.sqlclient是放在什么地方啊?是不是放在代码的最前面?但是它不认识啊?
      

  5.   

    比如说你的页面的名字是default.aspx,你就把它放在default.aspx.vb的最前面!
      

  6.   

    给你一段vb代码吧!
     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ClickDim ZKcommunicate As New ZKCommunicate()
                Dim strMember As String = ZKcommunicate.login(txtUserID.Text, txtPasswd.Text)
                If strMember = "1" Then
                    Response.Redirect("Upload.aspx")
                Else
                Page.RegisterStartupScript("warnings", "<script>alert('用户名与密码不一致!');</script>")            End If
    end sub
     Public Function login(ByVal UserID As String, ByVal Password As String) As String
            Dim strsql As String
            strsql = "select *  from ZK_AP_Resume_User where User_Name='" & UserID & "' and User_Passwd='" & Password & "' "
            objCommCommunciate = New SqlCommand(strsql, objConnCommunciate)
            objConnCommunciate.Open()
            Dim Reader As SqlDataReader = objCommCommunciate.ExecuteReader
            Try
                If Reader.Read Then
                    Return "1"
                Else
                    Return "0"
                End If
            Finally
                Reader.Close()
                objConnCommunciate.Close()        End Try    End Function
      

  7.   

    dim ds as  dataset=new dataset("Myset")
    dim da as sqlDataAdapter=new sqlDataAdapter("sql 语句",connection)
    da.fill(ds,"tt")
    if ds.tables("tt").rows.count>=0 then 
       response.write("您是合法用户")
    else
       response.write("您输入的帐户错误")
    end if 
    ds.clear()
      

  8.   

    说明:
        1.txtUserID.Text, txtPasswd.Text分别为用户名和密码输入框传出两个值给login过程,
        2.过程login是在公共类里面写的
      

  9.   

    无论你用什么编辑器,你检查你的代码的最前面的三行,是否是以下:
    <%@ Import NameSpace="System.Data.SQLClient" %>
    <%@ Import NameSpace="System.Data" %>
    <%@ Page Language="vb" Debug="True" %>
    如果没有你就加上,你的
    Dim objReader As SqlDataReader
    的语句就可以运行成功。
    其它的判断方法你看上面的贴子吧,已经说的很详细了。PS:你也是用VB.net的啊?太好了,我也是的。呵呵
      

  10.   

    对了,这个代码:
    Debug="True"
    是帮助你调试的,如果运行测试成功,发布的时候把这个代码给删除了
    然后在Web.Config的里面加上Debug="False"
    这样可以提高性能!
      

  11.   

    如果你有清华大学翻译的Wrox出版社的《Asp.net高级编程》书第14章第675页上面,有使用数据库做用户认证的详细示例,你可以看看,说的非常详细!