This article shows you how to connect to a MySQL database using the MySQL Connector for .NET. I will also show you how you can update MySQL database records using C#.
- Install Visual Studio 2008 or Visual Studio 2010
- Install MySQL database on your local machine
- MySQL database admin tool that allows you to create a database and run SQL statements. I am using phpMyAdmin which is a web interface.
- Download and install MySQL Connector.
Run the XAMPP application and it will automatically install Apache server, MySQL database,
and FileZilla. After installing check whether these
services are running or not. The following XAMPP control panel shows which of those services are currently running.
Now the following steps will show how to connect to a MySQL database using C#.
Open MySQL Admin page and create a new database.
After creating the new database, create a new table.
After creating the new table, open Visual Studio and click on New Project and name the project.
It will open the new project, then click
on Solution Explorer (F4), right click on “Reference” to add a new reference into the project. Reference those two
.dll files to the
project (MySql.dll (Win apps), MySql.web.dll (Web apps)).
Add namespace to the project.
Create a MySQL connection string.
The following code will insert the data into MySQL table.
The following function will load the data from the table and bind it into a
The final result is shown on the window form: