Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 如何在一个sql参数内传递多个整数值?_Vb.net_Ado.net - Fatal编程技术网

Vb.net 如何在一个sql参数内传递多个整数值?

Vb.net 如何在一个sql参数内传递多个整数值?,vb.net,ado.net,Vb.net,Ado.net,我有一个具有以下条件的存储过程: WHERE (Transaction_tbl.dtime BETWEEN @fromDate AND @toDate) AND (Location_tbl.Locid IN (@locations)) 我有一个列表框,它将@locations参数填充为一个整数,还有两个DateTimePicker控件,分别用于@fromDate和@toDate 我的列表框值如下所示: cnt = LSTlocations.SelectedItems.Count

我有一个具有以下条件的存储过程:

WHERE (Transaction_tbl.dtime BETWEEN @fromDate AND @toDate)   
  AND (Location_tbl.Locid IN (@locations))
我有一个列表框,它将@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
我想将此列表项值传递给我的存储过程…如何 这样做


如何修改此代码以将多个整数标识符作为@locations参数传递,以便我可以在列表框中选择多个项目?

将locations参数更改为字符串

选择项目 进入位置 来自dbo。split@locations",

您可以在此处找到拆分函数:

您必须更改查询以加入locations临时表

然后从您的VB传递一个逗号斜角字符串,该字符串包含所有选定位置的项目

大概是这样的:


[String].Join,LSTlocations.Items.CastOf ListItem.WhereFunctioni i.Selected。[选择]Functioni i.Value.ToArray

参数用于单个值,因此在使用参数时,您需要创建与列表中相同数量的参数。您是否检查过:先生..我使用的是VB.net我在VB.net中是新的..您能告诉我如何在VB.net中执行相同的操作吗?这只有在您同时使用mysql.actulayy locid时才有帮助整数…那么我如何传递字符串你说的位置参数改变字符串…实际上我必须传递整数值我如何改变位置参数。。?就像你建议的那样,把它改成一个字符串,就像上面的几行一样。但这是你需要做出的众多改变之一。您还需要更改SP并将列表框中的所有选定项转换为字符串。我已经提供了每个阶段要做什么的细节。我假设你有做这些事情的基本能力。
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) ' <= ???