日期:2014-05-18  浏览次数:20456 次

这段代码不登陆时 连接数据库没问题,但Session变量有值后就出错?

这段代码不登陆时   连接数据库没问题,但两个Session变量有值后,即当用户登陆
就出错,请帮忙看一下:


<script   language= "vb "   runat= "server ">
Sub   page_load(sender   as   Object,e   as   EventArgs)
dim   Identify   as   Integer   =   Session( "Identify ")   '   权限身份
dim   id   as   String     =   Session( "id ") '登陆者身份ID
Dim   conn     as   New   OleDbConnection()
Dim   cmd   as   New   OleDbCommand()
dim   SqlStr   as   String
conn.ConnectionString   =   "Provider=Microsoft.Jet.OLEDB.4.0;   Data   Source   =   "   &   Server.MapPath( "data/qrms.mdb ")  
conn.open()
cmd.Connection   =   conn
Select   case   identify
case   1 '如果选择的是管理员
                        SqlStr   =   "select   aid   from   admin   where   aid= ' "   &   id   &   " ' "
case   2 '如果选择的是教师
                        SqlStr   =   "select   tid   from   teacher   where   tid= ' "   &   id   &   " ' "
case   else '如果选择的是学生
                SqlStr   =   "select   xuehao   from   student   where   xuehao= ' "   &   id   &   " ' "
end   Select
'response.Write(sqlstr)
'exit   sub
'sqlstr   =   "select   xuehao   from   student   where   xuehao=   '2004415515 ' "
                        cmd   =   New   OleDbCommand(SqlStr,conn)
                      Dim   ObjReader   As   OleDbDataReader   =   Cmd.ExecuteReader()
                        If   ObjReader.Read()   Then
Select   case   Identify
case   1
response.Redirect( "admin/default.aspx ")
case   2
response.Redirect( "./Teacher_main.aspx ")
case   else
response.Redirect( "./Student_main.aspx ")
end   Select
Else
response.Redirect( "./error.aspx?error=inValid ")
end   if
end   Sub
</script>

------解决方案--------------------
你的ID变量在数据库里是字符串还是数字型的?如果是数字,那你那条SQL语句就有问题了吧?