I want to know how can I create a complete-fully crud operations using MySQL as a database and show/populate data in a ListView control. Also, in the process, connect to the database using a module with Ado.net or ODBC.
Please, Im a new on this kind of topics and currently Im studying computer science and I want to become a Visual Basic .Net programmer.
Firstly, don't use a ListView. Use a DataGridView. It is a genuine grid control. As for the data access code, here's an example I previously wrote for SQL Server:
Private connection As New SqlConnection("connection string here")
Private adapter As New SqlDataAdapter("SELECT ID, Name, Quantity, Unit FROM StockItem", _
Private table As New DataTable
Private Sub InitialiseDataAdapter()
Dim delete As New SqlCommand("DELETE FROM StockItem WHERE ID = @ID", Me.connection)
Dim insert As New SqlCommand("INSERT INTO StockItem (Name, Quantity, Unit) VALUES (@Name, @Quantity, @Unit)", Me.connection)
Dim update As New SqlCommand("UPDATE StockItem SET Name = @Name, Quantity = @Quantity, Unit = @Unit WHERE ID = @ID", Me.connection)
Me.adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey
Private Sub GetData()
'Retrieve the data.
'The table can be used here to display and edit the data.
'That will most likely involve data-binding but that is not a data access issue.
Private Sub SaveData()
'Save the changes.
The code for MySQL would be pretty much identical, but using types from the MySql.Data.MySqlClient namespace instead of the System.Data.SqlClient namespace. To have access to those types, you will need to download and install Connector/Net from the MySQL web site.
Note that that code was written as though it would be added to a form. You can make some small adjustments if it's not, e.g. make GetData a function that returns the DataTable and SaveData take the DataTable as an argument.