我有一个像这样的表值参数
CREATE TYPE dbo.Loc AS TABLE(Lo integer);
我的存储过程如下所示:
ALTER PROCEDURE [dbo].[T_TransactionSummary]
@startDate datetime,
@endDate datetime,
@locations dbo.Loc readonly
..........................
...........................
WHERE (Transaction_tbl.dtime BETWEEN @fromDate AND @toDate)
AND (Location_tbl.Locid IN (select Lo from @locations))
我有一个包含多个项目的列表框。我可以从列表框中选择多个项目。如何将多个Locationid传递给我的存储过程?
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
不兼容
为什么我收到此错误?