Sunday, 30 December 2012 13:54

using MYSQL database in asp.net 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 -
http://www.mysql.com/products/connector/

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
id=root;password=mridul;";

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

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

more details - http://dev.mysql.com/

Read 3094 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.