当前位置:编程学习 > C#/ASP.NET >>

关于调用session函数的问题

--------------------编程问答-------------------- http://download.csdn.net/source/2452790,
sessionhelp类,可以写成dll以备不时之需! --------------------编程问答--------------------      写得有点麻烦、 --------------------编程问答-------------------- 写得太复杂了,其实,只用一个Session保存这整个对象就可以了。 --------------------编程问答-------------------- 1. 如果在当前页需使用其他页面,则在开头应写入
<!--#include file=路径/其他页.asp -->

2. Session的使用,如果Session在其他页成功被赋值,那没在规定时间范围内都可以跨页面使用,例如:
<span>名字:<%=Session("strName")%></span>
--------------------编程问答--------------------

Dim strID,strName,strCollege,strMajor,intBalance
Session("strID")=conn.execute("select * from users where ID='"&strID&"')
Session("strName")=conn.execute("select * from users where Name='"&strName&"')
Session("strCollege")=conn.execute("select * from users where College='"&strCollege&"')
Session("strMajor")=conn.execute("select * from users where Major='"&strMajor&"')
Session("intBalance")=conn.execute("select * from users where Balance='"&intBalance&"'

你返回的是一个数据表,确用Session来记录???!!!!

建议好好学习一下SQL

-_______-!!! --------------------编程问答-------------------- 登录页:

<%
if request("Submit") ="登录" then
     sql="select * from users where 登录名 = "&"'"&request("name")&"'"&"and 密码="&SQLstr(request("pwd"))
     set rs = CreateObject("ADODB.Recordset")
     set rs=conn.execute(sql)
      if not rs.eof then
         session("ABCD")=rs("ID")&" "&rs("Name")&" "&rs("College")&" "&rs("Major")&"<br>同学你好,欢迎使用四川大学一卡通系统<br>您的账户余额为"&rs("intBalance")
      else
         response.write "<script>"
 response.write "alert(""没有这个用户或密码错误!"");"
 response.write "window.location.href='default.asp';"
 response.write "</script>"
      end if
end if
%>


在需要页内使用:
<span>登录信息:<%=Session("ABCD")%></span> --------------------编程问答--------------------
Dim strID,strName,strCollege,strMajor,intBalance
Session("strID")=conn.execute("select * from users where ID='"&strID&"')
Session("strName")=conn.execute("select * from users where Name='"&strName&"')
Session("strCollege")=conn.execute("select * from users where College='"&strCollege&"')
Session("strMajor")=conn.execute("select * from users where Major='"&strMajor&"')
Session("intBalance")=conn.execute("select * from users where Balance='"&intBalance&"'


Session("****")这个好像是存的整个表吧 --------------------编程问答-------------------- 我还是不太明白

我登陆界面已经做好了

已经登陆成功了

然后就需要在登录后的页面显示个人信息

session("****")这个我是看的书 --------------------编程问答--------------------
<%

Dim strID,strName,strCollege,strMajor,intBalance
Session("strID")=conn.execute("select strID from users where ID='"&strID&"')
Session("strName")=conn.execute("select strName from users where Name='"&strName&"')
Session("strCollege")=conn.execute("select strCollege from users where College='"&strCollege&"')
Session("strMajor")=conn.execute("select strMajor from users where Major='"&strMajor&"')
Session("intBalance")=conn.execute("select intBalance from users where Balance='"&intBalance&"')

Label1.Text=Session("strID")
Label2.Text=Session("strName")
Label3.Text=Session("strCollege")
Label4.Text=Session("strMajor")
Label5.Text=Session("intBalance")

Response.write strID&" "strName&" "strCollege&" "strMajor&"<br>"
Response.write"同学你好,欢迎使用四川大学一卡通系统<br>"
Response.write"您的账户余额为"&intBalance
%>



<form action="data/data_show.asp" name="right" method="post">
<tr>
<td></td>
<td><asp:Label ID="Label1" runat="server"></asp:Label></td>
<td><asp:Label ID="Label2" runat="server"></asp:Label></td>
<td><asp:Label ID="Label3" runat="server"></asp:Label></td>
<td><asp:Label ID="Label4" runat="server"></asp:Label></td>
</tr>
</table>
</form>
--------------------编程问答-------------------- session 一个id就够了吧
剩下的都可以用id查询出来 --------------------编程问答-------------------- 好复杂哦。。。 --------------------编程问答-------------------- 还没见过这种写法呢。。。
学习了。。。
帮你顶一个。。加油喽。。 --------------------编程问答-------------------- Dim strID,strName,strCollege,strMajor,intBalance//你这里是干什么呀?定义变量吗???你现在是什么语言?C#里的话,你不能这样定义,变量是要指定类型的,如

int strID;


Session("strID")=conn.execute("select * from users where ID='"&strID&"')
strID=Session("strID")//你这里是做啥????你到底是在什么语言下的嘛?

Session["strID"]=conn.execute("select * from users where ID='"&strID&"')
strID=Convert.ToInt32(Session["strID"]);//我这里改为C#下使用的

//我总感觉楼主的语言不对书,

哎,看习惯了C#的优雅,看别的一些语言,还真是有点郁闷了 --------------------编程问答-------------------- 通过ID取出所有的
dv=conn.execute("select strID from users where ID='"&strID&"')
Session["strID"]=dv.table.row[0]["ID"].tostring();
Session["strName"]=dv.table.row[0]["Name"].tostring();
以下类推 我记得括号是中括号不是小括号 --------------------编程问答-------------------- 我的写法是C#的 --------------------编程问答--------------------
引用 12 楼 zhoulingsmile 的回复:
还没见过这种写法呢。。。
学习了。。。
帮你顶一个。。加油喽。。


这是asp的写法,不是.net

--------------------编程问答--------------------
引用 13 楼 likevs 的回复:
Dim strID,strName,strCollege,strMajor,intBalance//你这里是干什么呀?定义变量吗???你现在是什么语言?C#里的话,你不能这样定义,变量是要指定类型的,如

int strID;


Session("strID")=conn.execute("select * from users where ID='"&strID&"……



我是看的asp
我看的asp上就是这样定义的呀strID

我是真的很菜鸟
我压根就不懂这个
逼我写代码
太恼火了 --------------------编程问答-------------------- 杯具呀,看来CSDN得另开个ASP专区了

楼上的你别火,代码这东西,得慢慢来 --------------------编程问答-------------------- 谢谢大家,我已经写出来了 --------------------编程问答-------------------- 汗,你写得成一堆啦。

分开写,别写的那么麻烦! --------------------编程问答-------------------- LZ也太强悍了吧  居然用那么多Session 存储数据

这样服务器的压力比较大 --------------------编程问答-------------------- 建议用主键ID查询,输入到SESSION,代表唯一一个用户,否则数据库设计问题会带来多个记录
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,