[英]operand type clash: int is incompatible with utblProgramAllotment[user defined table type]
My C# code: 我的C#代码:
var Message = new SqlParameter("Message", SqlDbType.VarChar, 8000);
Message.Direction = ParameterDirection.Output;
var UserId = new SqlParameter("UserId ", SqlDbType.BigInt);
UserId.Value = Convert.ToInt64(System.Web.HttpContext.Current.Session["UserIDKey"]);
var utblProgramAllotment = new SqlParameter("utblProgramAllotment", SqlDbType.Structured);
utblProgramAllotment.Value = dtProgrammeAllotments;
utblProgramAllotment.TypeName = "dbo.utblProgramAllotment";
try
{
db.Database.ExecuteSqlCommand(
"exec uspInsertUpdateProgrammeAllotment @UserId , @utblProgramAllotment, @Message OUTPUT",
UserId, utblProgramAllotment, Message);
}
catch (Exception ex)
{
vm.Message = ex.Message.ToString();
Errorlog.WriteErrorlog(ex, "Programme Allotment", "");
and my procedure accepts: 我的程序接受:
ALTER PROCEDURE [dbo].[uspInsertUpdateProgrammeAllotment]
(
@utblProgramAllotment AS utblProgramAllotment READONLY,
@UserId Bigint,
@Message VARCHAR(8000) OUTPUT
)
And the user defined table type is 用户定义的表类型是
CREATE TYPE [dbo].[utblProgramAllotment] AS TABLE(
[ProgrammeScheduleIDKey] [bigint] NOT NULL,
[ProposalDetailsIDKey] [bigint] NOT NULL,
[SanctionOrderIDKey] [bigint] NOT NULL,
[ProgrammeIDKey] [bigint] NOT NULL,
[EmployeeIDKey] [bigint] NOT NULL,
[DistrictIDKey] [bigint] NOT NULL,
[TargetGroupIDKey] [bigint] NOT NULL,
[ProgrammeTitleIDKey] [bigint] NOT NULL,
[ProgramMode] [varchar](3) NOT NULL,
[ProgrammeDescription] [varchar](500) NOT NULL,
[ScheduleStartDateDt] [datetime] NULL,
[ApprovalDt] [datetime] NOT NULL,
[ScheduleEndDateDt] [datetime] NULL,
[ProgrammeVenue] [varchar](250) NOT NULL,
[NoofParticipants] [bigint] NOT NULL,
[Remarks] [varchar](500) NOT NULL,
[AccountsRemarks] [varchar](250) NOT NULL,
[ExamDateDt] [datetime] NULL,
[ProgrammeTitle] [varchar](250) NOT NULL,
[DeletedFlg] [bit] NOT NULL
)
I am sending a data table to a sql stored procedure. 我正在将数据表发送到sql存储过程。 When I try to pass this data table from my c# it shows an exception as operand type clash: int is incompatible with utblProgramAllotment this is user defined table type
当我尝试从我的C#传递此数据表时,它将操作数类型冲突显示为异常:int与utblProgramAllotment不兼容,这是用户定义的表类型
If you're going to pass a request to execute a stored procedure across as ad-hoc text rather than specifically as a stored procedure execution, then the parameter order should match: 如果要通过临时文本而不是专门作为存储过程执行传递执行存储过程的请求,则参数顺序应该匹配:
exec uspInsertUpdateProgrammeAllotment @utblProgramAllotment, @UserId ,
@Message OUTPUT
Or you should name the parameters: 或者您应该命名参数:
exec uspInsertUpdateProgrammeAllotment @UserId = @UserId ,
@utblProgramAllotment = @utblProgramAllotment,
@Message = @Message OUTPUT
When used with the
@parameter_name=value form
, parameter names and constants do not have to be supplied in the order in which they are defined in the module.与
@parameter_name=value form
,不必按在模块中定义的顺序提供参数名和常量。 However, if the@parameter_name=value
form is used for any parameter, it must be used for all subsequent parameters.但是,如果将
@parameter_name=value
形式用于任何参数,则必须将其用于所有后续参数。
and, 和,
If parameter names are not specified, parameter values must be supplied in the order defined in the module.
如果未指定参数名称,则必须按照模块中定义的顺序提供参数值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.