看看老外都没有解决的问题

lnwuyaowei 2005-11-20 07:31:32
以下内容来自网址:http://forums.asp.net/959573/ShowPost.aspx
==========================
问题:
==========================
SqlDatasource parameter question
In SqlDataSource you can have several types of in parameters.

Control Parameter
QueryString Parameter
Form Parameter
Session Parameter
Cookie Parameter
Profile Parameter
My problem is I want my SqlDataSource to use the current logged in users Guid as the parameter for my Source.
I have solved this by Creating a Label control and assining the guid to this label and then using the control parameter for my SqlDataSource.
It works but it seems like a very akward way of doing this.

I have googled a couple of days in search for a good solution but I can't find it. Is there any way of using MemberShip.GetUser().ProviderUserKey
as the in parameter for a Datasource
回答:
===================================================================
Re: SqlDatasource parameter question

You can do something like this,

<SelectParameters>
<asp:Paramter Name=userGuid type="string" />
</SelectParameters>

with your sqlDataSource_selecting event
e.Command.Parameters("@userGuid").Value = MemberShip.GetUser().ProviderUserKey

解决:
==============================
Re: SqlDatasource parameter question

Thanks a lot. That worked very good.

Strange there isn't a default guid parameter to datasources as I would guess this is a very common situation.

A user put something into the database and you would like to show this for him next time he is logged in.
=====
但是:
=====
这个解决方法在asp.net2005express英文正式版中并不能用,出错提示如下:
Input string was not in a correct format.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.FormatException: Input string was not in a correct format.
=====





...全文
135 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
lnwuyaowei 2005-11-21
  • 打赏
  • 举报
回复
UP一下.
lnwuyaowei 2005-11-20
  • 打赏
  • 举报
回复
我用的是asp.net2005EXPRESS的正式英文版,而他的解答也是基于BETA2这个版本的,所以您测试是正常的。
MemberShip.GetUser().ProviderUserKey,这个取值没有问题,这段代码暂时不需要扩展MEMBERSHIP表。
SQLSERVER2005 EXPRESS没有装,用的是asp.net2005中自已带的那个版本。
谢谢楼上的解答。
zeusvenus 2005-11-20
  • 打赏
  • 举报
回复
这个问题刚用VS.NET 2005 Beta2试了下,没有出现你遇到的错误。
但是关于他说的要将用户登录过后数据源类型存下来,需要扩展membership表。
楼主装SQL SERVER2005 EXPRESS了吗?上面的问题可能是程序没有从你的membership表中取到数据导致的。关于membership的详细介绍,可以参考msdn webcast苏鹏王洪超他们的讲座,msdn网站上提供下载。
studydotnet 2005-11-20
  • 打赏
  • 举报
回复
太长了,不想看,不知道发这有什么意思?

62,047

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧