【问题标题】:Stored procedure is not returning values in MVC 5存储过程未在 MVC 5 中返回值
【发布时间】:2015-03-16 13:29:07
【问题描述】:

我想执行一个存储过程并将结果返回给视图,调试后我的参数被传递到存储过程中,但它什么也没返回并最终出错

传入字典的模型项的类型为 System.Data.Entity.Infrastructure.DbRawSqlQuery`1[SocialAuthentication.Models.User s,但此字典需要 SocialAuthentication.Models.Users 类型的模型项。

我知道我已经将模型声明为字符串预期的输出不同我该如何修复它。

我的模型

public class Users
{   
    public string Name { get; set; }
    public string Email { get; set; }
}

查看

@using (Html.BeginForm("Contact", "Home"))
{
  <input id="Text1" type="text" name="txtOne" />
  <input id="Button1" type="submit" value="button" />
}

控制器

[HttpPost]
public ActionResult Contact()
{
  string textboxValue = Request.Form["txtOne"];
  var result = db.Database.SqlQuery<Users>("usp_searchuser, @UserInput", new SqlParameter("@UserInput", textboxValue));
  return View(result);  
}

存储过程

CREATE procedure usp_searchuser --'Sara Nani'
    @UserInput varchar(50)
As
Begin
    select 
        Email, Name 
    from 
        tblEmployee 
    where 
        Name = @UserInput
End

【问题讨论】:

标签: c# sql-server-2008 asp.net-mvc-5


【解决方案1】:

在您的通话中,usp_searchuser 之后不应有逗号。这使它成为非法的 SQL 查询。

【讨论】:

    猜你喜欢
    • 2010-11-02
    • 2020-12-11
    • 1970-01-01
    • 1970-01-01
    • 2020-07-30
    • 2010-11-02
    • 2015-11-06
    • 2021-06-13
    • 2017-07-12
    相关资源
    最近更新 更多