从C#向SQL传递带有其他参数的表类型时出错

时间:2018-07-15 12:22:29

标签: sql-server vb.net

我正在将带有少量其他参数的表类型从C#传递到存储过程,但是我收到错误信息-

  

字符串或二进制数据将被截断。该声明已经   终止。

下面是在SQL-

中定义的类型
CREATE TYPE [dbo].[UT_ExcludedStates2] AS TABLE(
[StateID] [int] NULL,
[StateInitial] [varchar](2) NULL,  
[IsActive] [int] NULL
)

在C#-

中定义的数据表
Dim dt1 As DataTable = New DataTable("TableChanged")
                dt1.Columns.Add("StateID", GetType(System.Int32))
                dt1.Columns.Add("StateInitial", GetType(System.String))
                dt1.Columns.Add("IsActive", GetType(System.Int32))

这里我要传递给存储过程-

Dim oSqlParam(9) As SqlParameter
                oSqlParam(0) = New SqlParameter("@RecId", RecordId)
                oSqlParam(1) = New SqlParameter("@RecName", recordName)
                oSqlParam(2) = New SqlParameter("@DealCode", dealCode)
                oSqlParam(3) = New SqlParameter("@CompanyNumber", CompanyNumber)
                oSqlParam(4) = New SqlParameter("@Active", Active)
                oSqlParam(5) = New SqlParameter("@ExcludeAllPlans", excludeAllPlans)
                oSqlParam(6) = New SqlParameter("@ExcludeAllStates", excludeAllStates)
                oSqlParam(7) = New SqlParameter("@ModifiedBy", ModifiedBy)
                oSqlParam(8) = New SqlParameter("@planCode", strPlanCodes)
                oSqlParam(9) = New SqlParameter("@UT_ExcludedStates", dtStates)

                DataSupplier.ConnectOpen(ConnectString())
                iIsUpdate = DataSupplier().GetScalarValueFromStoredProc2("PROC1", oSqlParam)
                DataSupplier().ConnectClose()
                Return iIsUpdate

过程的参数如下-

@RecId int=0,
@RecName varchar(30),
@DealCode varchar(30),
@CompanyNumber varchar(5),
@Active int,
@ExcludeAllPlans int,
@ExcludeAllStates int,
@ModifiedBy varchar(30)='',
@planCode varchar(200)='',
@UT_ExcludedStates UT_ExcludedStates2 READONLY

关于相同的问题,我已经浏览了好几篇文章,但没有任何帮助。我想念什么吗?

0 个答案:

没有答案