这里是VB的新手。有没有什么简单或简单的方法可以将我的选中列表框中的5个选中项转换为字符串,以便我可以将它们保存在mySQL数据库中?或者更简单的东西?到目前为止我的代码是这样的。
Try
cnn.Open()
com = New MySqlCommand("SELECT id FROM columns WHERE cname ='" & TextBox1.Text & "'", cnn)
cdr = com.ExecuteReader
If cdr.HasRows Then
cdr.Close()
cnn.Close()
MsgBox("This Table has already been created!")
TextBox1.Focus()
Exit Sub
End If
cdr.Close()
com = New MySqlCommand("INSERT into column1, column2, column3, column4, column5, cname) VALUES('" ??? "', '" & TextBox1.Text &"')", cnn)
com.ExecuteNonQuery()
cnn.Close()
MsgBox("Attendance Table has been created.")
Catch ex As Exception
If Not cnn.State = ConnectionState.Closed Then
cnn.Close()
End If
MsgBox(ex.ToString)
End Try我现在正纠结于在插入MySQLCommand之后输入什么值。任何帮助都将不胜感激。提前谢谢你
发布于 2015-04-08 15:40:07
试试这段代码。这将以逗号分隔的字符串形式返回选中列表框中的选中项目。
Private Function getChkdBoxString() As String
Dim myChkdBoxes = CheckedListBox.CheckedItems 'rename CheckedListBox to the name of the checked list box that you have used
Dim chkBoxString As String = ""
For Each chkBox In myChkdBoxes
chkBoxString = chkBox.ToString & "," & chkBoxString
Next
Return chkBoxString
End Sub
发布于 2020-01-20 10:22:32
使用下面的代码,很简单,但对我来说很有效:
单击event add:
Dim mycheckedlist = CheckedListBox1.CheckedItems
Dim checkedstr As String = ""
For Each chkBox In mycheckedlist
checkedstr = chkBox.ToString & "," & checkedstr
Next
(here you add your code to insert the checkstr
variable as a string into your database)通过这种方式,您可以获得以逗号分隔的字符串形式的值列表。
https://stackoverflow.com/questions/29508494
复制相似问题