我有一个像下面这样的数组
(0) = "apple"
(1) = "orange"
如何向数组中的所有项目添加一些字符串?就像苹果变成“苹果”,橙色变成“橙色”
已编辑
Private Sub test()
Dim txtReader As TextReader = New StreamReader("data.csv")
Dim parser = New CsvParser(txtReader)
Dim str As String = ""
'Ignore first line
parser.Read()
While True
Dim row = parser.Read()
If row Is Nothing Then
Exit While
End If
str &= $"({String.Join(",", row)}),"
End While
str_record = str.TrimEnd(",")
End Sub
Private Sub Model_Insert()
Dim data As String = ""
Dim query As String = "INSERT INTO main_item(item_code,item_name,item_desc,item_unitprice,item_barcode,dept_id,cat_id,gst_id,set_item,active)" &
"VALUES " & str_record & ""
Using cmd = New MySqlCommand(query, conn)
cmd.ExecuteNonQuery()
End Using
End Sub
我试图创建一个字符串并在 INSERT INTO 中使用它
使用For
循环:
Dim array = {"apple", "orange"}
For i As Int32 = 0 To array.Length - 1
array(i) = $"'{array(i)}'"
Next
如果您还不能使用字符串插值,请使用String.Format
(或字符串连接):
For i As Int32 = 0 To array.Length - 1
array(i) = String.Format("'{0}'", array(i))
Next
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句