如何使用vb.net将列表框中的所有项目保存到MYSQL数据库

时间:2013-04-01 06:05:45

标签: mysql vb.net listboxitem

这是我的代码,我只能保存第一项。我需要将整个列表保存在一个数据库列中。感谢您的帮助。

Dim mysql As String = "UPDATE tbl_item SET my_item = (@myitems) WHERE id = '" & Label6.Text & "'"


Dim mycmd As New MySqlCommand(mysql, sConnection)

Dim values As New List(Of String)

values.Add(ListBox1.Items.Add(values))

Dim sqlParam As New MySqlParameter With {.ParameterName = "@myitems", .DbType = DbType.String}

mycmd.Parameters.Add(sqlParam)

Dim i As Integer

For i = 0 To values.Count - 1
    sqlParam.Value = (ListBox1.Items(i) & ";")
    mycmd.ExecuteNonQuery()
Next

1 个答案:

答案 0 :(得分:0)

Dim i As Integer

For i = 0 To values.Count - 1
         If sqlparam.value = "" Then
            sqlparam.value = listbox1.Items(i) & ";"
        Else
            sqlparam.value = sqlparam.value & listbox.Items(i) & ";"
        End If

    Next       
   mycmd.ExecuteNonQuery() 

如果此代码失败,请尝试将mycmd.execute ....放在..