我想做一个网上考试系统,不同的用户名登陆不同的页面,string a="select UserType from DengLu where UserName="+this.TextBox1.Text+ " and UserPwd="+this.TextBox2.Text+"";
这句查找表中用户名和密码等于输入文本框那行的返回TYpe那个字段,然后判断如果是S,就进入学生页面,如果是T就进入老师的页面。可是为什么不好使呀
this.sqlDataAdapter1.SelectCommand.Parameters["@name"].Value=this.TextBox1.Text;
this.sqlDataAdapter1.SelectCommand.Parameters["@pwd"].Value=this.TextBox2.Text;
this.sqlDataAdapter1.Fill(this.dataSet11);
if(this.dataSet11.DengLu.Rows.Count!=0)
{
string a="select UserType from DengLu where UserName="+this.TextBox1.Text+ " and UserPwd="+this.TextBox2.Text+"";
if(a=="s")
{
this.Response.Redirect("xuesheng.aspx");
}
if(a=="t")
{
this.Response.Redirect("laoshi.aspx");
}
}
else
{
this.Label3.Text="登陆失败";
}
这句查找表中用户名和密码等于输入文本框那行的返回TYpe那个字段,然后判断如果是S,就进入学生页面,如果是T就进入老师的页面。可是为什么不好使呀
this.sqlDataAdapter1.SelectCommand.Parameters["@name"].Value=this.TextBox1.Text;
this.sqlDataAdapter1.SelectCommand.Parameters["@pwd"].Value=this.TextBox2.Text;
this.sqlDataAdapter1.Fill(this.dataSet11);
if(this.dataSet11.DengLu.Rows.Count!=0)
{
string a="select UserType from DengLu where UserName="+this.TextBox1.Text+ " and UserPwd="+this.TextBox2.Text+"";
if(a=="s")
{
this.Response.Redirect("xuesheng.aspx");
}
if(a=="t")
{
this.Response.Redirect("laoshi.aspx");
}
}
else
{
this.Label3.Text="登陆失败";
}
//在这里加入查询语句,用DataReader来取得字段,然后
if (DR.Reader())
{
string a = DR["UserType"].ToString();
}
else
{}
然后再是 if(a=="s")
{
this.Response.Redirect("xuesheng.aspx");
}
if(a=="t")
{
this.Response.Redirect("laoshi.aspx");
}
改成string b 刚才没看仔细
Private Sub TryIt(ByVal sender As Object)
Dim uid As String = ""
Dim pwd As String = ""
uid = Trim(username.Text)
pwd = password.Text
uid = Replaces(uid)
If Trim(uid) <> "" And Trim(pwd) <> "" Then
Dim sql As String = "select uid,pwd,type from YourTable Where uid='" & uid & "' and pwd='" & pwd & "'"
Dim connection As New System.Data.SqlClient.SqlConnection("connectionstring,sql server 2005")
Dim cmd As New System.Data.SqlClient.SqlCommand(sql, connection)
Dim reader As System.Data.SqlClient.SqlDataReader
connection.Open()
reader = cmd.ExecuteReader()
If reader.Read Then
Dim sType As String = ""
If Not IsDBNull(reader.Item(2)) Then
If Trim(reader.Item(2)) <> "" Then
sType = Trim(reader.Item(2))
'you need create differeent session value
Select Case sType
Case "s"
Session("s") = "session"
reader.Close()
cmd.Dispose()
connection.Close()
Response.Redirect("url")
Case Else
Session("y") = "session"
reader.Close()
cmd.Dispose()
connection.Close()
Response.Redirect("url")
End Select
Else
reader.Close()
cmd.Dispose()
connection.Close()
Page.Dispose()
Response.Write("we're sorry,we cannot found this username or your input error.")
End If
Else
reader.Close()
cmd.Dispose()
connection.Close()
Page.Dispose()
Response.Write("we're sorry,we cannot found this username or your input error.")
End If
Else
reader.Close()
cmd.Dispose()
connection.Close()
Page.Dispose()
Response.Write("we're sorry,we cannot found this username or your input error.")
End If
Else
Response.Write("validate input.")
Page.Dispose()
End If
End Sub
Private Function Replaces(ByVal s As String) As String
Try
s = Replace(s, "'", "")
'all string will replaced
s = Trim(s)
Return s
Catch ex As Exception
Return "error"
End Try
End Function
</script><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Microsoft .NET Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID ="username" runat ="server" ></asp:TextBox>
<asp:TextBox ID ="password" runat ="server" TextMode ="Password" ></asp:TextBox>
<asp:Button runat ="server" OnClick ="TryIt" UseSubmitBehavior ="true" />
</div>
</form>
</body>
</html>