Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do I use Listview to delete MySQL DB records
#6
Thanks for your response - really appreciate it. While waiting, I started playing around and managed to come up with this after watching a couple of Youtube videos and searching online:

HERE'S MY SOLUTION - PLEASE CRITIQUE IT:
[code2=vbnet]Private Sub ButtonDelete_Click(sender As System.Object, e As System.EventArgs) Handles ButtonDelete.Click

'FOR MySQL DATABASE USE
Dim dbConn As New MySqlConnection(String.Format("Server={0};Port={1};Uid={2};Password={3};Database=accounting", FormLogin.ComboBoxServerIP.SelectedItem, My.Settings.DB_Port, My.Settings.DB_UserID, My.Settings.DB_Password))
Dim dbTable As New DataTable
Dim dbQuery As String = ""
'Dim dbCmd As New MySqlCommand

Dim confirmation As DialogResult = MessageBox.Show("This action will delete the selected Customer Credit Cards from the database.", "Are you sure?", MessageBoxButtons.YesNo)
If (confirmation = Windows.Forms.DialogResult.Yes) Then
'Delete Records
Try
If ListViewRecords.Items.Count > 0 Then

For i = ListViewRecords.Items.Count - 1 To 0 Step -1
If ListViewRecords.Items(i).Checked = True Then

dbQuery = "DELETE FROM cc_master WHERE ccID = '" & ListViewRecords.Items(i).Text & "'"
Dim dbAdapter As New MySqlDataAdapter(dbQuery, dbConn)
dbAdapter.Fill(dbTable)
Call getRecordCount()
Call loadRecords()

End If
Next i
End If
Catch ex As Exception
MessageBox.Show("A DATABASE ERROR HAS OCCURED" & vbCrLf & vbCrLf & ex.Message & vbCrLf & _
vbCrLf + "Please report this to the IT/Systems Helpdesk at Ext 131.")
End Try
dbConn.Close()
dbConn.Dispose()
End If
End Sub[/code2]
//Kismet


Messages In This Thread
Re: How do I use Listview to delete MySQL DB records - by kismetgerald - 11-25-2012, 11:47 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Open Zip files into a listview box Worf 2 13,988 09-20-2014, 10:14 AM
Last Post: Worf
  How can I read a link from mysql databse??? mnxford 9 33,063 04-12-2013, 06:27 PM
Last Post: brandonio21
  Listview and Krypton help brco900033 1 10,411 11-01-2012, 01:04 AM
Last Post: Snake_eyes
  [SOLVED] MySQL Update Query - What am I doing wrong? kismetgerald 11 43,370 10-18-2012, 07:16 PM
Last Post: brandonio21
  How do I fill my form with MySQL data based on Combobox? kismetgerald 8 26,737 10-14-2012, 09:05 PM
Last Post: brandonio21
  Read and delete lines brco900033 6 22,591 09-16-2012, 09:38 AM
Last Post: brandonio21
  Help with creating an INSERT statement using MySQL kismetgerald 4 16,770 08-30-2012, 03:03 PM
Last Post: brandonio21
  MySQL Database Issue Moldraxian 7 29,068 08-13-2012, 08:58 PM
Last Post: brandonio21
  MySql Database Queries in VB.Net Moldraxian 6 22,406 07-26-2012, 03:44 PM
Last Post: Moldraxian
  How to Package MySql Connector and MySql Program? Moldraxian 3 14,774 07-20-2012, 12:23 PM
Last Post: brandonio21

Forum Jump:


Users browsing this thread: 1 Guest(s)