非预期的操作数类型冲突:表类型在执行存储过程时与int不兼容

时间:2013-10-30 11:44:15

标签: sql-server vb.net stored-procedures listbox

我有Table值参数,如下所示:

CREATE TYPE [dbo].[Loc] AS TABLE(Lo integer)

我的存储过程获取位置ID,如下所示:

 ALTER PROCEDURE [dbo].[T_TransactionSummary] 
 @startDate datetime,  
 @endDate datetime,
@locations dbo.Loc readonly
..........................
.........................
WHERE     (Transaction_tbl.dtime BETWEEN @fromDate AND @toDate) 
AND  EXISTS (SELECT 1 FROM @locations WHERE lo = Location_tbl.Locid)  

我的locid字段是整数这个locid来自我的listbox.if我选择一个项目1 locid将来。如果我选​​择2项目2 locid将来..我有一个ListBox填充@locations参数(一个整数),我把我的列表框值像这样

cnt = LSTlocations.SelectedItems.Count
  Dim dtlist As New DataTable()
    Dim locid As Integer
    If cnt > 0 Then
        For i = 0 To cnt - 1
            dtlist.Columns.Add(locid, GetType(Integer))
            Dim locationanme As String = LSTlocations.SelectedItems(i).ToString
            locid = RecordID("Locid", "Location_tbl", "LocName", locationanme)
            dtlist.Rows.Add(locid)
        Next
End If
 Dim da As New SqlDataAdapter
        Dim ds As New DataSet
        Dim cmd23 As New SqlCommand("T_TransactionSummary", con.connect)
        cmd23.CommandType = CommandType.StoredProcedure
        Dim tvp1 As SqlParameter = cmd23.Parameters.AddWithValue("@locations", dtlist)
         tvp1.SqlDbType = SqlDbType.Structured
         tvp1.TypeName = "dbo.Loc"
        da.SelectCommand = cmd23
        da.Fill(ds)

但我得到的错误是这样的:

  

操作数类型冲突:表类型与int

不兼容

我的代码和存储过程有什么问题

1 个答案:

答案 0 :(得分:0)

也许是因为你在创建SqlCommand时没有为存储过程指定前两个参数(@startdate,@ enddate)