Str.Split 用于未知数量的值,每个值都有插入语句



如果我不知道逗号分隔值的数量,如何存储每个值,然后为每个值执行插入语句。因此,如果str的值是123456,321654,321545(我不知道会提前有3个值),如何拆分所有em并进行3次插入?我想它会是每个陈述?但我不确定如何使用 .split 做到这一点?有人可以给我一些方向吗?我下面的代码将只返回第一个值。谢谢

Dim str As String = Session("List")
    str = str.Split(",")(1)
    Return

你是对的,这将是一个foreach.Split方法返回一个string[]

For Each s As String In str.Split(","c)
    ' build the insert statement and execute
Next

你需要拆分字符串。 试试这个:

Dim str As String = DirectCast(Session("List"), String)
For Each item As String In str.Split(","c)
  ' Do stuff with item here
Next item