操作数类型冲突:int与utblProgramAllocation[用户定义的表类型]不兼容
本文关键字:类型 定义 不兼容 用户 utblProgramAllocation 冲突 int 操作数 | 更新日期: 2023-09-27 18:12:01
我的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", "");
我的程序接受:
ALTER PROCEDURE [dbo].[uspInsertUpdateProgrammeAllotment]
(
@utblProgramAllotment AS utblProgramAllotment READONLY,
@UserId Bigint,
@Message VARCHAR(8000) OUTPUT
)
用户定义的表格类型是
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
)
我正在向sql存储过程发送一个数据表。当我试图从c#传递这个数据表时,它显示了一个异常操作数类型冲突:int与utblProgramAllocation不兼容这是用户定义的表类型
如果您要将执行存储过程的请求作为特别文本而不是特定的存储过程执行来传递,那么参数顺序应该匹配:
exec uspInsertUpdateProgrammeAllotment @utblProgramAllotment, @UserId ,
@Message OUTPUT
或者你应该命名参数:
exec uspInsertUpdateProgrammeAllotment @UserId = @UserId ,
@utblProgramAllotment = @utblProgramAllotment,
@Message = @Message OUTPUT
参见EXECUTE
:
当与
@parameter_name=value form
一起使用时,参数名称和常量不必按照模块中定义的顺序提供。但是,如果@parameter_name=value
形式用于任何参数,则必须用于所有后续参数。
和,
如果未指定参数名称,则必须按照模块中定义的顺序提供参数值。