登录代码问题
在其他处抄了这么一段程序,确定是对的 就是下面Session,Response提示未声明,请帮忙看一下
Imports System.Data.SqlClient
Dim Username, Userpwd As String
Username = Me.用户登录_Renamed.Text.Trim()
Userpwd = Me.Text1.Text.Trim()
Dim myconnection As Sqlconnection = New sqlconnection( "server=COMPUTER;Database=NEW;uid=sa;Password=; ")
Dim searchcmd As String
searchcmd = "select 密码 from 登录 where 用户名= ' " & 用户登录_Renamed.Text & " ' "
Dim mycommand As Sqlcommand = New Sqlcommand(searchcmd, myconnection)
mycommand.connection.open()
Dim myreader As Sqldatareader = mycommand.Executereader()
If myreader.read() Then
Session( "用户名 ") = Username
Response.BufferOutput = True
response.redirect( "长治医学院后勤学生管理系统.vb ")
Else
Response.BufferOutput = True
Response.Redirect( "unlogin.aspx ")
End If
mycommand.Connection.Close()
[解决办法]
response.redirect( "长治医学院后勤学生管理系统.aspx ")
[解决办法]
//连接数据库:
<appSettings>
<add key= "sqllink " value= "server=yfq-001;uid=ADM;pwd=sdadm;database=DBMT50 "> </add>
</appSettings>
//登录
string connstr=System.Configuration.ConfigurationSettings.AppSettings[ "sqllink "];
SqlConnection conn=new SqlConnection(connstr);
conn.Open();
string sql= "select count(*) as icount from sysoper where logname= ' "+this.usrname.Text+ " ' ";
SqlCommand comm=new SqlCommand(sql,conn);
SqlDataReader dr1=comm.ExecuteReader();
dr1.Read();
string count=dr1[ "icount "].ToString();
dr1.Close();
if(count!= "0 ")
{
sql= "select * from sys where logname= ' "+this.usrname.Text+ " ' ";
SqlCommand comm1=new SqlCommand(sql,conn);
SqlDataReader dr=comm1.ExecuteReader();
dr.Read();
string drpwd=dr[ "logpass "].ToString();
dr.Close();
if(drpwd==this.usrpwd.Text)
{
this.Session[ "logid "]=this.usrname.Text.Trim();
if(dr[ "PLCName "].ToString()== " ")
{
this.Session[ "level "]= "1 ";
}
if(dr[ "PLCName "].ToString()!= " ")
{
this.Session[ "level "]= "2 ";
this.Session[ "plcname "]=dr[ "PLCName "].ToString();
}
this.Response.Redirect( "main.aspx ");
}
else
{
this.Response.Write( " <script> alert( '登录密码错误! ') </script> ");
}
}
if(count== "0 ")
{
this.Response.Write( " <script> alert( '没有这个用户! ') </script> ");
}