I have a series of two checkbox groups. If a checkbox is checked in the first series of checkboxes values are updated in a sql database based on the second series of checkboxes. Here is the code :


VB.net Code:
  1. Private Sub ArrowButton1_Click(sender As Object, e As EventArgs) Handles ArrowButton1.Click
  2.         '*****************Pas toe op gekose kultivars en klasse ***********************************
  3.         Dim konneksie As New SqlConnection
  4.         konneksie.ConnectionString = "Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\Administrator\Desktop\SKEDULERING\Skedulering6\Skedulering6\SkeduleringsDatabasis6.mdf;Integrated Security=True"
  5.         konneksie.Open()
  6.         Dim opdragdeleteGroepperingsKode, opdragdeleteGroepperingsBeskrywing, opdragreseed, opdragskepkode, opdragskepbeskrywing, opdragdeleteGroepperingsGekies, opdraghaallaastekommauit As New SqlCommand
  7.  
  8.         Dim i As Integer = 1
  9.  
  10.         For Each row As DataGridViewRow In Me.Skedulering2DataGridView.Rows
  11.  
  12.             Dim DGVKultklas As String = row.Cells("Kultklas").Value
  13.             Dim kode As String = ""
  14.             Dim beskrywing As String = ""
  15.             Dim checked As Boolean = CType(row.Cells("checkBoxColumn").Value, Boolean)
  16.             If checked Then
  17.  
  18.                 If Me.SlaagCheckBox.Checked = True Then
  19.  
  20.                     If kode = "" Then
  21.                         kode = "GrSl"
  22.                     Else
  23.                         kode = kode & ",GrSl"
  24.                     End If
  25.  
  26.                     opdragskepkode.Connection = konneksie
  27.                     opdragskepkode.CommandText = "UPDATE skedulering2 " &
  28.                             "SET   GroeperingsKode       = CONCAT( '" & kode & "',   slaagsuiker )  " &
  29.                             "WHERE kultklas = '" & DGVKultklas & " '"
  30.                     opdragskepkode.ExecuteNonQuery()
  31.  
  32.  
  33.                 End If
  34.  
  35.  
  36.                 If Me.SnoeiCheckBox.Checked = True Then
  37.                     If kode = "" Then
  38.                         kode = "GrSn"
  39.                     Else
  40.                         kode = kode & ",GrSn"
  41.                     End If
  42.                     opdragskepkode.Connection = konneksie
  43.                     opdragskepkode.CommandText = "UPDATE skedulering2 " &
  44.                                                 "SET   GroeperingsKode       = CONCAT( '" & kode & "',   PruningMethod )  " &
  45.                                                 "WHERE kultklas = '" & DGVKultklas & " '"
  46.                     opdragskepkode.ExecuteNonQuery()
  47.  
  48.                 End If
  49.  
  50.                 If Me.OesCheckBox.Checked = True Then
  51.                     If kode = "" Then
  52.                         kode = "GrOe"
  53.                     Else
  54.                         kode = kode & ",GrOe"
  55.                     End If
  56.                     opdragskepkode.Connection = konneksie
  57.                     opdragskepkode.CommandText = "UPDATE skedulering2 " &
  58.                                                 "SET   GroeperingsKode       = CONCAT( '" & kode & "',   HarvestMethod )  " &
  59.                                                 "WHERE kultklas = '" & DGVKultklas & " '"
  60.  
  61.                     opdragskepkode.ExecuteNonQuery()
  62.  
  63.                 End If
  64.  
  65.             End If
  66.  
  67.             '  MsgBox("Finale groepperingskode (" & i & ") : " & kode)
  68.             i = i + 1
  69.         Next
  70.  
  71.     End Sub

The code works as I want except after the update the sql table only has the last concatinated value. I suspect I have to pass the concatination to my vb.net "kode". However I have no idea how. Any help would be much appreciated.