How to Connect MySQL Database with C# Application

in #utopian-io6 years ago (edited)

The first, I want to tell that the tutorial is very basic learn. But it's still useful and proper if you are a very beginner in programming and trying to solve your own problem yourself.

MySQL is very popular and very easy-to-use DBMS (Data Base Management System), that if you are a very beginner, I think you have to start with this database before you try to higher system like Oracle, SQL Server, etc. It's light size, cannot contain 'so many' data, and the most important IT'S FREE.

Then about the C# language. It's a Desktop Language. A language 'near' with C and C++ which developed by MIcrosoft. It's 'near' too with ASP and Visual Basic, because it's using .NET Framework. So, if you had a basic in C or C++ and ASP or Visual Basic, you can understand this language easily.

So, let's begin...

Download MySQL Driver for. NET

The first, to make a connection between the MySQL and C#, we need a connector driver. We can get the connector from https://dev.mysql.com/downloads/file/?id=406540.

If you already downloaded the file, the open the file... Click Next.

01.JPG

Just choose the Typical to make the default feature.

02.JPG

Select the Install and just wait until finished.

03.JPG

Now, you have a MySQL Driver Connector on your computer.

Connect the MySQL to C# Application

After the installation has finished. Your C# IDE (compiler) added the MySQL reference automatically. In this case I use SharpDevelop as my IDE (compiler) because it's lighter and free. But, common people using Visual Studio in General. It's not a problem. There's no many differences between Sharp Develop and Visual Studio, you will understand it easily. If you want to use SharpDevelop, can get it here http://www.icsharpcode.net/OpenSource/SD/Download/Default.aspx.

Open your SharpDevelop Application, then click File -> New -> Solution. In the New Project Dialog, select Windows Application, then give the name of your Solution or program. Then Create.

04.JPG

Find the Reference Menu, then Add Reference.

05.JPG

On Add Reference Dialog, find MySQL.Data, MySQL.Data.CF, MySQL.Data.Entity, MySQL.Web, then Add the references.

06.JPG

Double Click your form, to show the Source of your form.

07.JPG

Then put this code on your source. This code has a function to load and call the library of MySQL.Data Reference.

using MySql.Data;
using MySql.Data.MySqlClient;

View of the code.

08.JPG

Now your application can access the MySQL database. REMEMBER: you must have to create the database before.

I think that is what I can share right now. Modify as you want it for a better result. Hope this helpful for you. Let's discuss for make it better next time.

Thanks for reading.

Cheers
.
.
.
.
.
Reference:
http://jagocoding.com/tutorial/169/Koneksi_Database_Mysql_dengan_C



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

Your contribution cannot be approved because it is not as informative as other contributions. See the Utopian Rules. Contributions need to be informative and descriptive in order to help readers and developers understand them.

You can contact us on Discord.
[utopian-moderator]

Thanks for this post. I'm began in C# programming

Mantabs, semoga approve :)

Move to Italy. I mean it: they know about living in debt; they don't care. I stayed out there for five months while I was making a film called 'Order Of Death,' and they've really got it sussed. Nice cars. Sharp suits. Great food. Stroll into work at 10. Lunch from 12 till three. Leave work at five. That's living!

Coin Marketplace

STEEM 0.17
TRX 0.13
JST 0.030
BTC 56519.24
ETH 2991.31
USDT 1.00
SBD 2.16