I have a stored procedure which returns 1 row and 1 column containing a string.
我有一个存储过程,返回包含字符串的1行和1列。
I am using the SqlQuery method from db.Database to try and return this method as a string. However when I checked the return value it returns the name of the stored procedure and the parameters I am trying to pass.
我正在使用db.Database中的SqlQuery方法尝试将此方法作为字符串返回。但是当我检查返回值时,它返回存储过程的名称和我试图传递的参数。
var val = db.Database.SqlQuery<string>(string.Format("{0} @QuestionnaireID", model.ObjectiveB.StoredProcedure.SpName),
new SqlParameter("QuestionnaireID", model.ProjectId));
This is what is returned
这是返回的内容
I've also tried using
我也试过用
.FirstOfDefault()
and
.ToList()
But still none return the value I want, onlt the name of the stored procedure and it's parameter. Any help would be great!
但是仍然没有返回我想要的值,包括存储过程的名称和它的参数。任何帮助都会很棒!
1 个解决方案
#1
1
Simple answer is something like this:
简单的答案是这样的:
var response = Db.Database.SqlQuery<string>("EXEC procName @p1={0}, @p2={1}, @p3={2}", v1, v2, v3);
var strResponse = resp.First();
Make sure to check the response object for errors first.
确保首先检查响应对象是否有错误。
#1
1
Simple answer is something like this:
简单的答案是这样的:
var response = Db.Database.SqlQuery<string>("EXEC procName @p1={0}, @p2={1}, @p3={2}", v1, v2, v3);
var strResponse = resp.First();
Make sure to check the response object for errors first.
确保首先检查响应对象是否有错误。