Wednesday, November 19, 2008

Connecting MySql With Asp.net Using ODBC Drivers

0 comments 11/19/2008
Sign up to receive our site updates!

MySQL and ODBC

A more supported format for connecting to MySQL from a C# .NET web application is by using the common ODBC driver. First, you will need to install the MySQL ODBC driver http://www.mysql.com/products/connector/odbc on your PC. This same driver (MyODBC) is usually installed on most web servers. As such, you may have no other choice except to use ODBC for connecting to MySQL.

Connecting to the MySQL database from your C# ASP .NET web application using ODBC is very similar to the above example. You just change a small part of each command definition from MySQL to Odbc.


using System.Data;

using System.Data.Odbc;


public partial class odbc : System.Web.UI.Page

{


static string s = "driver={Mysql odbc 3.51 driver}; sever =localhost; user id=root;password=admin;database=temp;option=3";

OdbcConnection con = new OdbcConnection(s);


protected void Page_Load(object sender, EventArgs e)

{

OdbcDataAdapter da = new OdbcDataAdapter("select * from emp", con);

DataSet ds = new DataSet();

da.Fill(ds, "emp");

GridView1.DataSource = ds;

GridView1.DataBind();

}

}





Your Ad Here

0 comments:

Respects for your's Questions & Opinions

  • Friends
  •  

    Recent Posts

    New Comments

    Copyright 2008 All Rights Reserved Tech Tasks Template by Rajesh Kumar Chekuri