Sunday, 30 December 2012 13:54

using MYSQL database in website

Written by 
Rate this item
(0 votes)

MySQL provides drivers for .Net enabling building database
applications by their appropriate languages.

to connect to Mysql database in .net application first
Mysql connector must be downloaded here -

after installing the connector the reference of
MySql.Data and other appropriate drivers must be added
to the application project.

after that the example codes shows how to use MySql db in
.net project -

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

namespace MySql
public partial class addstud : System.Web.UI.Page
MySqlCommand cmd;
MySql.Data.MySqlClient.MySqlConnection conn;
MySqlDataReader reader;

protected void Page_Load(object sender, EventArgs e)
string connect = "Server=localhost;Database=petreg;user

string query = "SELECT id,breed from breeds";
conn = new MySql.Data.MySqlClient.MySqlConnection(connect);
using (cmd = new MySqlCommand(query, conn))
breedDropDownList.DataSource = cmd.ExecuteReader();
breedDropDownList.DataValueField = "id";
breedDropDownList.DataTextField = "breed";

in the above program a DropDownList is populated by MySql
database data.

more details -

Read 2960 times
Super User

Email This email address is being protected from spambots. You need JavaScript enabled to view it.

Latest discussions

  • No posts to display.