我有一个这样的存储过程:
ALTER PROCEDURE [dbo].[T_TransactionSummary]
@locations nvarchar
AS
BEGIN
..............
.............
AND (Location_tbl.Locid IN (@locations))
我的 locid 字段是整数,这个 locid 来自我的列表框。如果我选择一个项目,1 个 locid 会出现。如果我选择 2 个项目,2 个 locid 会出现。我有一个填充 @locations 参数(整数)的列表框,我像这样取了我的列表框值
cnt = LSTlocations.SelectedItems.Count
Dim list As New List(Of Integer)
Dim locid As Integer
If cnt > 0 Then
For i = 0 To cnt - 1
Dim locationanme As String = LSTlocations.SelectedItems(i).ToString
locid = RecordID("Locid", "Location_tbl", "LocName", locationanme)
list.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
cmd23.Parameters.Add("@locations", SqlDbType.Int).Value = String.Join(",", list)
da.SelectCommand = cmd23
da.Fill(ds)
现在我来自列表框的 locationid 仅传递给存储过程 1、2、3。但存储过程总是取第一个值(我的意思是在这种情况下取 1)。