2012-07-17 168 views
9

我有一个存储过程与签名没有映射从对象类型System.RuntimeType存在一个已知的托管提供原生型

PROCEDURE [dbo].[spValidateID] 
    @ScanCode  VARCHAR(50), 
    @Name   VARCHAR(50) = NULL OUTPUT, 
    @ScanTime  DATETIME = NULL OUTPUT, 
    @ValidationCode INT = 0 OUTPUT 

这应该返回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); 
} 

但在运行此我m如果从对象类型System.RuntimeType不存在任何映射错误 到已知的托管提供原始类型。

任何想法?

+0

ExecuteStoreQuery显示错误,因为不包含定义。 – 2017-06-18 09:12:49

回答

4

您缺少您的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! 
相关问题