Click here to Skip to main content
15,915,867 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm having a problem thinking how could i insert the items listed in listbox and retreive it for update.

What I have tried:

This is the code for the ListBox populated with database:
VB
'Populate the ListBox with personnelName from personnel '
      Try
          myConnection = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Nikko Jaze Fabellon\Documents\ASRASIM.accdb")
          myConnection.Open()
          ds = New DataSet
          tables = ds.Tables
          da = New OleDbDataAdapter("SELECT [FirstName],[LastName] from [Personnel] where [Status] = 'Activated' ", myConnection)
          da.Fill(ds, "Personnel")
          Dim view1 As New DataView(tables(0))
          With personnelList
              .DataSource = ds.Tables("Personnel")
              .DisplayMember = "FirstName"
              .ValueMember = "LastName"
              .SelectedIndex = 0
          End With

          myConnection.Close()

      Catch ex As Exception
          MessageBox.Show(ex.Message)
      End Try


And this the code in adding items from the populated listbox with database to the other listbox: (Thanks for A.Griffin for helping me with this code)
VB
<pre>
        Try
            Dim str As String
            Dim drv As DataRowView = CType(personnelList.SelectedItem, DataRowView)
            str = CStr(drv.Row.Item("FirstName")) & " " & CStr(drv.Row.Item("LastName"))
            ListBox1.Items.Add(str)
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
Posted
Updated 2-Feb-18 0:12am
v3

1 solution

am not sure, this is your question however the correct syntax would be like below
Quote:
str = "Insert into ServiceRecords([ClientName],[Address],[TimeStarted],[TimeEnded],[OpDate],[FloorDrain Quantity],[FloorDrain Clogged],[FloorDrain F/R]) Values(?,?,?,?,?,?,?,?)"
str = "Insert into ServiceRecords([ClientName],[Address],[TimeStarted],[TimeEnded],[OpDate],[FloorDrain Quantity],[FloorDrain Clogged],[FloorDrain F/R]) Values(@ClientName,@Address,@TimeStarted,@TimeEnded,@OpDate,@FloorDrainQuantity,@FloorDrainClogged,@FloorDrainFR)"


cmd.Parameters.Add(New OleDbParameter("@ClientName", CType(clientNameText.Text, String)))
       cmd.Parameters.Add(New OleDbParameter("@Address", CType(addressText.Text, String)))
       cmd.Parameters.Add(New OleDbParameter("@TimeStarted", CType(timeStartedText.Text, String)))
       cmd.Parameters.Add(New OleDbParameter("@TimeEnded", CType(timeEndedText.Text, String)))
       cmd.Parameters.Add(New OleDbParameter("@OpDate", CType(datePicker.Text, Date)))
       cmd.Parameters.Add(New OleDbParameter("@FloorDrainQuantity", CType(fldQuantityText.Text, String)))
       cmd.Parameters.Add(New OleDbParameter("@FloorDrainClogged", CType(fldClcbox.CheckState, Boolean)))
       cmd.Parameters.Add(New OleDbParameter("@FloorDrainFR", CType(fldFinRecText.Text, String)))
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900