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

  5. These are really amazing and valuable websites you have shared with us. Thanks for the informative post.
    WordPress development company in Chennai

  6. Nice! you are sharing such helpful and easy to understandable blog. i have no words for say i just say thanks because it is helpful for me.

    Dot Net Training in Chennai | Dot Net Training in anna nagar | Dot Net Training in omr | Dot Net Training in porur | Dot Net Training in tambaram | Dot Net Training in velachery

  7. Great Article IoT Projects for Students

    Deep Learning Projects for Final Year

    JavaScript Training in Chennai

    JavaScript Training in Chennai

    The Angular Training covers a wide range of topics including Components, Angular Directives, Angular Services, Pipes, security fundamentals, Routing, and Angular programmability. The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer. Angular Training


Add your comments here

Back to Top