开发者

How do I set the Where clause of an EntityDataSource in the code-behind

开发者 https://www.devze.com 2023-03-21 22:52 出处:网络
PaymentsDueEntityDataSource.ContextTypeName = \"Bills.DAL.BillsEntities\"; PaymentsDueEntityDataSource.EnableFlattening = false;
        PaymentsDueEntityDataSource.ContextTypeName = "Bills.DAL.BillsEntities";
        PaymentsDueEntityDataSource.EnableFlattening = false;
        PaymentsDueEntityDataSource.EntitySetName = "tblPayments_Due";

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

        PaymentsDueEntityDataSource.Incl开发者_如何学Cude = "tblType, tblRepeat";
        PaymentsDueEntityDataSource.EnableUpdate = true;

When I delete the Where clause, my gridview returns all records. When I hardcode the same string which is generated from the HttpContexxt string in the HTML, my gridview returns the proper records. However, when I try to use the code above, I get an out of scope message:

'kwingat' could not be resolved in the current scope or context. Make sure that all referenced variables are in scope, that required schemas are loaded, and that namespaces are referenced correctly. Near simple identifier, line 6, column 15.

Any Ideas?


I think you need to pass it as a parameter

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

精彩评论

暂无评论...
验证码 换一张
取 消