How about this :
Dim res as string = "SELECT ITEM FROM DETAIL WHERE TID='1'"
CMD = New MySqlCommand(res, con)
result = CMD.ExecuteReader()
Dim resultString as String = ""
Dim isFirstResult = True
while result.HasRows
result.Read()
If Not isFirstResult Then
resultString &= string.Format(",'{0}'",result("ITEM"))
Else
isFirstResult = False
resultString &= string.Format("'{0}'",result("ITEM"))
End If
end while
Or if you want to keep using the array but also need the single string version, you can convert the array using String.Join
:
Dim resultString As String = "'" & String.Join("','", array) & "'"
String.Join
is clever enough to add separator only if next element exists. So both approach above should produce the same result.