我有一个这样的存储过程:
ALTER PROCEDURE [dbo].[T_TransactionSummary]
@startDate datetime,
@endDate datetime,
@locations integer
AS
BEGIN
.................
................
WHERE (Transaction_tbl.dtime BETWEEN @fromDate AND @toDate)
AND (Location_tbl.Locid IN (@locations))
我有一个 ListBox 填充 @locations 参数(一个整数),以及两个 DateTimePicker 控件,@fromDate
我@toDate.
将我的列表框值设为:
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("@startDate", SqlDbType.NVarChar, 50, ParameterDirection.Input).Value = startdate
cmd23.Parameters.Add("@endDate", SqlDbType.NVarChar, 50, ParameterDirection.Input).Value = enddate
cmd23.Parameters.Add("@locations", SqlDbType.Int).Value = String.Join(",", list)
da.SelectCommand = cmd23
da.Fill(ds)
如果代码到达这里,我会收到这样的错误:
“无法将参数值从字符串转换为 Int32
我知道这行出错了
cmd23.Parameters.Add("@locations", SqlDbType.Int).Value = String.Join(",", list)
我想将参数转到像 1、2、3 这样的存储过程,只有我使用的是 vb.net。我的代码有什么问题..任何帮助都非常感谢..