Results 1 to 5 of 5

Thread: Save CheckedListBox To Database

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2008
    Posts
    5

    Save CheckedListBox To Database

    Hi, I am trying to save checked items from a CheckedListBox to a table in a database, I am using the following code:

    Dim conn As New OleDb.OleDbConnection("Provider=sqloledb;" & _
    "Data Source=KIM-LAPTOP;" & _
    "Initial Catalog=ScrcCardBase;" & _
    "User Id=sa;" & _
    "Password=sa")
    Dim oList As Object
    Dim strsql As String = ""
    Dim cmd1 As OleDb.OleDbCommand
    Try
    conn.Open()
    For Each oList In Me.clbSites.CheckedItems
    strsql = "INSERT INTO tblSiteAllocation (Site) VALUES ('" & oList & "')"
    cmd1 = New OleDb.OleDbCommand(strsql, conn)
    cmd1.ExecuteNonQuery()
    Next
    Catch ex As Exception
    MessageBox.Show(ex.Message)
    Finally
    conn.Close()
    End Try

    I am getting the following error message:
    Operator '&' is not defined for string "INSERT INTO tblSiteAllocation(S" and type 'DataRowView'.

    Any ideas as to what may be causing this.

    Or does anyone know of an easier way to save checkedlistbox data to a database.
    Thanks
    Last edited by Lacool; Apr 14th, 2010 at 09:27 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width