Monday, 15 July 2013

How To Connect To MySql Database in Asp.Net

How To Connect To MySql Database in Asp.Net ?
Connect To MySql Database in C# ?

Here I am going to Show how to Connect to mysql database using C#.

Step-1:

Just click link and down load the mysql connecter and install it in your computer.

Step-2:

After Installing go to your solution area of your project


Step-3:

Right Click on References and click on add Reference



 Step-4:
Choose .Net tab on the popup dialogue box

Step-5:
Choose Mysql.Data and press Ok













Step-6:
After That Mysql connecter will be added to project refrence





















Step - 7:
Write Your Code to access the MySql Database

<form id="form1" runat="server"> 
    <asp:GridView ID="gv_Data" runat="server" RowStyle-BackColor="Aqua" HeaderStyle-BackColor="Bisque" HeaderStyle-Font-Bold="true"></asp:GridView>

  </form> 

Step-8:

protected void Page_Load(object sender, EventArgs e)
{
 MySqlConnection con = new MySqlConnection("Server=localhost;DataBase=Demo;User=root;password=");
            con.Open();
            MySqlDataAdapter adpt = new MySqlDataAdapter("SELECT member_id,first_name FROM tbl_member", con);
            DataSet ds = new DataSet();
            adpt.Fill(ds);
            gv_Data.DataSource = ds.Tables[0].DefaultView;

            gv_Data.DataBind();
}

Result



No comments:

Post a Comment