Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do I use Listview to delete MySQL DB records
#4
Hey Brandon, I figured I'd share the code I'm using to populate my Listview. I'm calling this Sub on the FormLoad event.

[code2=vbnet]Private Sub loadRecords()
Dim dbConn As New MySqlConnection
Dim dbTable As New DataTable

dbTable.Clear()

Try
'FOR MySQL DATABASE USE
Dim dbQuery As String = ""
Dim dbCmd As New MySqlCommand
Dim dbAdapter As New MySqlDataAdapter
Dim i As Integer

If dbConn.State = ConnectionState.Closed Then
dbConn.ConnectionString = 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)
dbConn.Open()
End If

dbQuery = "SELECT *" & _
"FROM cc_master INNER JOIN customer ON customer.accountNumber = cc_master.customer_accountNumber"
With dbCmd
.CommandText = dbQuery
.Connection = dbConn
End With
With dbAdapter
.SelectCommand = dbCmd
.Fill(dbTable)
End With
ListViewRecords.Items.Clear()
For i = 0 To dbTable.Rows.Count - 1
With ListViewRecords
.Items.Add(dbTable.Rows(i)("ccID"))
With .Items(.Items.Count - 1).SubItems
.Add(dbTable.Rows(i)("ccNumber"))
.Add(dbTable.Rows(i)("ccExpireMonth"))
.Add(dbTable.Rows(i)("ccExpireYear"))
.Add(dbTable.Rows(i)("nameCOMPANY"))
End With
End With
Next
Catch ex As MySqlException
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()

End Sub[/code2]
//Kismet


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

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

Forum Jump:


Users browsing this thread: 1 Guest(s)