gpt4 book ai didi

c# - 如何在代码隐藏中设置 EntityDataSource 的 Where 子句

转载 作者:行者123 更新时间:2023-11-30 17:17:05 24 4
gpt4 key购买 nike

        PaymentsDueEntityDataSource.ContextTypeName = "Bills.DAL.BillsEntities";
PaymentsDueEntityDataSource.EnableFlattening = false;
PaymentsDueEntityDataSource.EntitySetName = "tblPayments_Due";

PaymentsDueEntityDataSource.Where = "it.UserName = " + HttpContext.Current.User.Identity.Name.ToString();

PaymentsDueEntityDataSource.Include = "tblType, tblRepeat";
PaymentsDueEntityDataSource.EnableUpdate = true;

当我删除 Where 子句时,我的 gridview 返回所有记录。当我对从 HTML 中的 HttpContextxt 字符串生成的相同字符串进行硬编码时,我的 gridview 返回正确的记录。但是,当我尝试使用上面的代码时,我收到一条超出范围的消息:

“kwingat”无法在当前范围或上下文中解析。确保所有引用的变量都在范围内,加载了所需的模式,并且正确引用了 namespace 。接近简单标识符,第 6 行,第 15 列。

有什么想法吗?

最佳答案

我认为你需要将它作为参数传递

PaymentsDueEntityDataSource.Where = "it.UserName = @UserID";
PaymentsDueEntityDataSource.WhereParameters.Add(new Parameter("UserID", TypeCode.Int32, + HttpContext.Current.User.Identity.Name.ToString()));

关于c# - 如何在代码隐藏中设置 EntityDataSource 的 Where 子句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6783686/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com