我有一个asp.net/vb.net
网络应用,需要将信息放入多行文字框中。如果用户在文本框中按下Enter键,则会下拉到下一行,并且可以输入更多数据。当它尝试转到数据库时,由于数据的表示方式而失败。我需要帮助循环遍历该字段并获取每个值。
这是数据在DataTable
0;0.123;0.234;0.345;...
我需要;
字符之间的每个值...所以我在想这样的事情?
If dbRow.Item("PV").ToString.Contains(";") Then
For Each symbol As String In DBTable.Rows
'get data b/w the ';'
Next
End If
非常感谢任何帮助
编辑:
If dbRow.Item("PV").ToString.Contains(";") Then
For Each s As String In dbRow.Item("PV").ToString
Dim fields() As String = s.Split(";"c)
For Each value As String In fields
.Append("'" & CDbl(value) & "'," & "SysDate,1)")
DBCommand.CommandText = myInsertIntoProperty_DataStringBuilder.ToString
DBCommand.ExecuteNonQuery()
myInsertIntoPropertyStringBuilder = New StringBuilder
Next
Next
Else
.Append("'" & CDbl(dbRow.Item("PV")) & "'," & "SysDate,1)")
End If
答案 0 :(得分:2)
你的意思是这样的吗?
Dim s As String In dbRow.Item("PV").ToString()
Dim fields() As String = s.Split(";"c)
For Each value As String In fields
' Do what you want with the value
Next
然后使用field(0)
,fields(1)
等访问每个值。然后,您可以将其转换为适当的类型,例如:
Dim value As Double = Double.Parse(fields(0), CultureInfo.InvariantCulture)