我有一个带签名的存储过程
PROCEDURE [dbo].[spValidateID]
@ScanCode VARCHAR(50),
@Name VARCHAR(50) = NULL OUTPUT,
@ScanTime DATETIME = NULL OUTPUT,
@ValidationCode INT = 0 OUTPUT
Run Code Online (Sandbox Code Playgroud)
这应该返回validationCode并填充名称和scanTime变量.我需要在调用时给它scanCode值.
在我的C#代码中,我这样做.
using (var context = new DBEntities())
{
var pScanCode = new SqlParameter("ScanCode", scanCode);
var opName = new SqlParameter("Name", name);
var opScanTime = new SqlParameter("ScanTime", scanTime);
var opValidationCode = new SqlParameter("ValidationCode", validationCode);
var test = context.ExecuteStoreQuery<int>("spValidateID @ScanCode, @Name, @ScanTime, @ValidationCode", pScanCode, opName, opScanTime, opValidationCode);
}
Run Code Online (Sandbox Code Playgroud)
但是在运行时遇到错误从对象类型System.RuntimeType到已知的托管提供程序本机类型不存在映射.
任何的想法??
您缺少sqlparameters和@的输出设置.您的代码应如下所示:
SqlParameter pScanCode = new SqlParameter("@ScanCode", ScanCode);
SqlParameter opName = new SqlParameter("@Name", name);
opName.Direction = System.Data.ParameterDirection.Output; //Important!
SqlParameter opScanTime = new SqlParameter("@ScanTime", scanTime);
opScanTime.Direction = System.Data.ParameterDirection.Output; //Important!
SqlParameter opValidationCode = new SqlParameter("@ValidationCode ", validationCode);
opValidationCode.Direction = System.Data.ParameterDirection.Output; //Important!
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10738 次 |
| 最近记录: |