.net中session值怎么在.aspx文件中引用
<asp:SqlDataSourceID="SqlDataSource1"runat="server"ConnectionString="<%$ConnectionStr...
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:EAIData %>"
SelectCommand="SELECT
[ProjectNO],
[ProjectName],
[ModifiedBy],
[ModifiedDate],
[UndertakeDate],
undertakeAdminstrator
FROM [tbProjectInfo] where undertakeAdminstrator=???">
</asp:SqlDataSource>
我想把 undertakeAdminstrator 等于页面传过来的Session["UserName"],请问这要怎么做? 展开
SelectCommand="SELECT
[ProjectNO],
[ProjectName],
[ModifiedBy],
[ModifiedDate],
[UndertakeDate],
undertakeAdminstrator
FROM [tbProjectInfo] where undertakeAdminstrator=???">
</asp:SqlDataSource>
我想把 undertakeAdminstrator 等于页面传过来的Session["UserName"],请问这要怎么做? 展开
4个回答
展开全部
session和application、response、request这些都是内置对象,不需要引用,可直接使用
如String s =Session["username"].ToString(),当然前提是你得把username存到session里去
存的话就直接Session["username"] = "xxxx";
如String s =Session["username"].ToString(),当然前提是你得把username存到session里去
存的话就直接Session["username"] = "xxxx";
追问
我刚刚进行了问题补充 ,帮忙看一下 谢谢
追答
=???的地方改成'" + Session["UserName"].ToString() + "'"
前提是Session["UserName"]必须有值
Session["UserName"]是个object,必须转换成String才能用+来拼接
展开全部
string a=Session["session名字"].toString() 这个事赋值
Session["haha"]=“123”; 这个是 开辟一个session的变量,叫做haha。给他赋值为"123"
SelectCommand="SELECT
[ProjectNO],
[ProjectName],
[ModifiedBy],
[ModifiedDate],
[UndertakeDate],
undertakeAdminstrator
FROM [tbProjectInfo] where undertakeAdminstrator=???">
改成
SelectCommand="SELECT
[ProjectNO],
[ProjectName],
[ModifiedBy],
[ModifiedDate],
[UndertakeDate],
undertakeAdminstrator
FROM [tbProjectInfo] where undertakeAdminstrator='"+Session["UserName"].toString()+"'">
Session["haha"]=“123”; 这个是 开辟一个session的变量,叫做haha。给他赋值为"123"
SelectCommand="SELECT
[ProjectNO],
[ProjectName],
[ModifiedBy],
[ModifiedDate],
[UndertakeDate],
undertakeAdminstrator
FROM [tbProjectInfo] where undertakeAdminstrator=???">
改成
SelectCommand="SELECT
[ProjectNO],
[ProjectName],
[ModifiedBy],
[ModifiedDate],
[UndertakeDate],
undertakeAdminstrator
FROM [tbProjectInfo] where undertakeAdminstrator='"+Session["UserName"].toString()+"'">
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:EAIData %>"
SelectCommand="SELECT
[ProjectNO],
[ProjectName],
[ModifiedBy],
[ModifiedDate],
[UndertakeDate],
undertakeAdminstrator
FROM [tbProjectInfo] where undertakeAdminstrator={UserName}">
<SelectParameters>
<asp:SessionParameter Name="UserName" SessionField="UserName" />
</SelectParameters>
SelectCommand="SELECT
[ProjectNO],
[ProjectName],
[ModifiedBy],
[ModifiedDate],
[UndertakeDate],
undertakeAdminstrator
FROM [tbProjectInfo] where undertakeAdminstrator={UserName}">
<SelectParameters>
<asp:SessionParameter Name="UserName" SessionField="UserName" />
</SelectParameters>
追问
报错 undertakeAdminstrator={UserName} 附近 有语法错误
追答
undertakeAdminstrator=@UserName
刚才笔误
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
<%=Session["UserName"]%> 在前台,试一下。
追问
试了一下 where undertakeAdminstrator='""' 编译通过了,运行报错
追答
断点。错误贴出来
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询