Retrieving and saving mysql database data to checkedlistbox in visual studio vb.net

  • Thread starter Thread starter wirejp
  • Start date Start date
W

wirejp

Guest
Hello,


I have trying to use KarenInstructor 's MSDN tutorial How to save and retrieve values from checkedlistbox to database to retrieve and save mysql database data to checkedlistbox in visual studio vb.net. However, the tutorial used a Microsoft Access database as the reference database. I am unable to modify the oledb.adapter connection string to work for a MySQL connection string. The code is : -


Public Class frmCheckListBoxFormDemo
Private BuilderAccdb As New OleDb.OleDbConnectionStringBuilder With
{
.Provider = "Microsoft.ACE.OLEDB.12.0",
.DataSource = IO.Path.Combine(Application.StartupPath, "Database1.accdb")
}
Private Sub LoadMe(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


clbCheckedListBox.SuspendLayout()

Dim dt As New DataTable

Using cn As New OleDb.OleDbConnection With
{
.ConnectionString = BuilderAccdb.ConnectionString
}

Using cmd As New OleDb.OleDbCommand With
{
.Connection = cn,
.CommandText =
<SQL>
SELECT
Identifier,
ItemIndex,
Item,
CheckedStatus
FROM
Items
</SQL>.Value
}

cn.Open()
dt.Load(cmd.ExecuteReader)

End Using
End Using

Dim LastIndex As Integer = 0

Try
For Each row As DataRow In dt.Rows

clbCheckedListBox.Items.Add(row.Field(Of String)("Item"))
LastIndex = clbCheckedListBox.Items.Count - 1

If row.Field(Of Boolean)("CheckedStatus") Then
clbCheckedListBox.SetItemChecked(LastIndex, True)
End If

Next

ActiveControl = clbCheckedListBox
clbCheckedListBox.SelectedIndex = 0
Finally
clbCheckedListBox.ResumeLayout()
End Try

End Sub


My goal is to populate a checkedlistbox with the Surname of people and a checkbox from the MySQL database. One should be able to check the checkboxes and save the updates back to the MySQL database.


Thank you in advance for your assistance

Continue reading...
 
Back
Top