我有一个类似的查询SELECT ITEM FROM DETAIL WHERE TID="1"
。这将返回类似的结果
m4、c1、f2、d5、k2
我DATAREADER
用来获取多值结果
这是代码
Dim res as string = "SELECT ITEM FROM DETAIL WHERE TID='1'"
CMD = New MySqlCommand(res, con)
result = CMD.ExecuteReader()
while result.HasRows
result.Read()
array(indeks) = result("ITEM")
end while
现在改为将结果一一存储到每个数组的索引中,
数组(0)=m4
数组(1)=c1,......
我想将所有这些存储到单个字符串变量中,格式为“m4”、“c1”、“f2”、“d5”、“k2”
格式是单引号和逗号(,)作为每个结果的分隔符,如上面的示例(逗号仅在仍有结果时出现)
我怎么能在 vb.net 中做到这一点?我正在使用 mysql 作为数据库
更新代码
Dim cnt As String = "select count(*) from detail where kode_faktur= '" & 1 & "' "
Dim max As Int32
CMD_sup = New MySqlCommand(cnt, conn.konek)
max = Convert.ToInt32(CMD_sup.ExecuteScalar())
CMD_sup.Connection.Close()
Dim result As MySqlDataReader
Dim resultString As String
Dim isFirstResult = True
Dim arayITEM() As String
Dim res As String = "select kode_brg from detail where kode_faktur= '" & 1 & "' "
CMD = New MySqlCommand(res, conn.konek)
result = CMD.ExecuteReader()
ReDim arayITEM(max)
If result.HasRows Then
For i As Integer = 0 To max - 1
result.Read()
arayITEM(i) = result("kode_brg")
Next
End If
resultString = "'" & String.Join("','", arayITEM) & "'"
'MsgBox("HASIL : " & resultString)
这是屏幕截图
我不需要在最后一个数组元素(,''
)末尾的分隔符