Connection with MySQL in

Many time we comes in a situation where we cannot use Sql Server with our application. There can be many problems like Budget,Resources. In such situation we think of a Database which can be a good alternative to Sql Server. at that time one names that comes in most of the developer is MySql as it is an open source database. In this tutorial we will discuss how to connect you application with MySql Database.

For making connection with MySQL in you have to do the following tasks.

  1. Download and install the MySQL dotnet connector. Click here to download.
  2. After installing the connector add the reference to the MySql.Data to your solution.

    Add Reference to MySql.Data

    Add Reference to MySql.Data

  3. Go to you class file and add the MySql.Data.MySqlClient namespace in your application
  4. Below is the code to make the connection and read the data from database.
    string constring = "Server=;Uid=Demo;Pwd=demo@123;Database=demo;";
    MySqlConnection connection = new MySqlConnection(constring);
    MySqlCommand command = new MySqlCommand("Select * from TBL_Student", connection);
    MySqlDataReader rdr = command.ExecuteReader();
    while (rdr.Read())
    	Studentinfo.Add (new Student(){
    		id = int.Parse(rdr["id"].ToString()),
    		name = rdr["name"].ToString()   
    	}) ; 
  5. After making the connection with the MySql database you can work as you are working with Sql Server.

Keep visiting  for more post.

Rajat Jain
Rajat Jain

Latest posts by Rajat Jain (see all)

  1. Avatar doudoune armani ea7 homme
  2. Avatar webpage
    • Avatar admin
  3. Avatar parajumpers rea
  4. Avatar web site
  5. Avatar doudoune north face homme
    • Avatar admin
  6. Avatar Mohammad
    • Avatar admin
  7. Avatar pjs doudoune prix

Leave a Reply

Your email address will not be published. Required fields are marked *