This is pretty hard initially as C# also has OLEDB, ODBC drivers to communicate with a database. However, I’ll be using none of these. Let me guide you through as I have enlightened:
Firstly, download the latest MySQL Connector/Net, for connecting to MySQL from .NET
Secondly, add a reference to your project, it is probably in C:\\Program Files\\MySQL\\MySQL Connector Net 5.0.7\\Binaries\\.NET 2.0 folder (it depends on your connector version), add the MySql.Data.dll file as a reference.
Thirdly, make your connection string, the following code will shows a standard MySQL connection string.
1 2 3 4 5 6 7 8 9 10 11 12 13 | using MySql.Data.MySqlClient; class Program { static void Main(string[] args) { string my_connection = "SERVER=localhost;" + "DATABASE=rabbit;" + "UID=root;" + "PASSWORD=;"; MySqlConnection connection = new MySqlConnection(my_connection); } } |
Lastly, you can make use of the Connector methods and class by reading Connector/NET Examples and Usage Guide
This marks the end of my simple tutorial in setting up C# with MySQL. When I am free, I will do how a tutorial on how to retrieve data or maybe how C# interact with MySQL !













