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中的HttpContexxt字符串生成的相同字符串时,我的gridview返回正确的记录。但是,当我尝试使用上面的代码时,我收到了超出范围的消息:
'kwingat'无法在当前范围或上下文中解析。确保所有引用的变量都在范围内,加载了所需的模式,并正确引用了名称空间。近简单标识符,第6行,第15列。
任何想法?
答案 0 :(得分:2)
我认为您需要将其作为参数传递
PaymentsDueEntityDataSource.Where = "it.UserName = @UserID";
PaymentsDueEntityDataSource.WhereParameters.Add(new Parameter("UserID", TypeCode.Int32, + HttpContext.Current.User.Identity.Name.ToString()));