如果我不知道逗号分隔值的数量,我该如何存储每个值,然后为每个值执行插入语句。因此,如果 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