-4

我有这样的表值参数:

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 来自我的列表框。如果我选​​择一个项目,1 个 locid 会出现。如果我选​​择 2 个项目,2 个 locid 会出现。我有一个填充 @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 不兼容

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

4

1 回答 1

0

可能是因为您在创建 SqlCommand 时没有为存储过程指定前两个参数(@startdate、@enddate)

于 2013-10-30T12:50:30.863 回答