Connect mysql database to c#

Connecting mysql database using c#
Connect mysql to
Connection between C# and mysql database
Inserting data from C# into mysql

Before connecting C# to mysql we have to install Mysql Connector/Net Download now

Here we using mysql database

Step to add MySql.Data to your project

Step 1:-
Right Click on your project and select Add Reference

Step 2:-
Click on Browse and move to C:\Program Files\MySQL\MySQL Connector Net 6.5.6\Assemblies\v4.0

Note:- Here MySQL Connector Net version is 6.5

 Step 3:-

Select MySql.Data.dll file and press ok

Now Write Program for connecting mysql to .net project

Herder file:-

using MySql.Data.MySqlClient;


string MyConString = "SERVER=localhost;" +
                "DATABASE=speed;" +
                "UID=root;" +

/* speed is database name, root is mysql username, test is mysql password */

MySqlConnection connection = new MySqlConnection(MyConString);
MySqlCommand command = connection.CreateCommand()

// open connection
// entry is mysql table name
//from,to and speedval are column names
string cmdText = "INSERT INTO entry (`from`, `to`, `speedval`) VALUES (@from, @to, @speed )";

                MySqlCommand cmd = new MySqlCommand(cmdText, connection);
                cmd.Parameters.AddWithValue("@from", Label1.Text);
                cmd.Parameters.AddWithValue("@to", Label2.Text);
                cmd.Parameters.AddWithValue("@speed", Label3.Text);

//close connection


  1. Thanh you,
    This topic is very good and useful.

  2. visit this for easy and short code for database access

  3. This is exactely what I long needed, thank you.

  4. Thanks for sharing valuable information. Your blogs were helpful to Dot NET learners. I
    request to update the blog through step-by-step. Also, find the Dot net news at Dot NET Online Training Bangalore


Add your comments here

Back to Top