【发布时间】:2013-10-21 16:50:02
【问题描述】:
我有一个这样的存储过程:
ALTER PROCEDURE [dbo].[T_TransactionSummary]
@locations nvarchar
AS
BEGIN
..............
.............
AND (Location_tbl.Locid IN (@locations))
我的 locid 字段是整数 这个 locid 来自我的列表框。如果我选择一个项目 1 locid 将会出现。如果我选择 2 项目 2 locid 将会出现.. 我有一个 ListBox 填充 @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)。
【问题讨论】:
-
您是否先进行了任何简单的调试?喜欢
PRINT @locations;? -
不,先生...为什么我必须这样做?
-
因为在这种情况下,它会显示您传递的值被截断。
标签: sql-server vb.net