我有一个这样的存储过程:
ALTER PROCEDURE [dbo].[T_TransactionSummary]
@locations integer
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)
如果代码到达这里,我会收到这样的错误:
"Failed to convert parameter value from a String to a Int32
我知道这行出错了
cmd23.Parameters.Add("@locations", SqlDbType.Int).Value = String.Join(",", list)
但我想将参数转到像 1、2、3 这样的存储过程,只有我使用的是 vb.net。我必须在我的代码中进行更改..任何帮助都非常感谢..