title: delete record from database in listview in vb
body: <p>I have a problem. In the properties of listview which is checkboxes = "True". Using this checkbox, I want to delete the data in listview and in the database. </p>
  
  <p>Below is the code:</p>
  
  <pre><code>If MessageBox.Show("Do you really want to DELETE this record?", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = DialogResult.No Then
  
          MsgBox("Operation cancel", MsgBoxStyle.Information, "Information")
  
      End If
  
      dbSource = "Data Source=LAILATUL-PC\SERVER;Initial Catalog=HotelManagementSystem;Integrated Security=True"
  
  
      Dim sql As String = "DELETE FROM [Room] WHERE Room_Code =  @code"
  
  
      Using con = New SqlConnection(dbSource)
          Using cmd = New SqlCommand(sql, con)
              con.Open()
  
              For Each lvItem As ListViewItem In ListViewRoom.Items
                  If lvItem.Checked Then
  
  
                      cmd.Parameters.AddWithValue("@code", ColumnRoomCode.Text)
  
                      cmd.ExecuteNonQuery()
                      lvItem.Remove()
  
                  End If
              Next
          End Using
      End Using
  </code></pre>
  
  <p>Using above code, only the data in listview is deleted. The data in the database not deleted.</p>
  
  <p>The interface for listviewitem:</p>
  
  <p><img src="https://i.stack.imgur.com/gfCnN.png" alt="enter image description here"></p>
  
  <p>Thank you if you all can help me. :)</p>