【发布时间】:2014-04-18 11:33:03
【问题描述】:
我正在尝试执行以下代码。我的目标是检查是否存在具有给定电子邮件 ID 的用户。
var result = userDbContext.users.SqlQuery("SELECT * FROM USERS WHERE @email='@emailValue'",
new SqlParameter("@email", "email"),
new SqlParameter("@emailValue","abc@mail.com"));
//new SqlParameter("p1", existingUser.password));
if (result.Count() == 0) //getting exception here
{
ViewBag.comment = "Sorry. We can not find your credentials";
return View();
}
但我在result.count() 遇到异常,不知道出了什么问题。
例外是:
"SqlParameter 已经被另一个包含 SqlParameterCollection"
我该如何解决这个问题?
【问题讨论】:
-
你不能参数化你的列名,你可以参数化你的值。
标签: c# asp.net-mvc-4