Home > ASP.NET > ASP.NET with MySql

ASP.NET with MySql

Here are the steps to connect your ASP.NET application with MySql Database.

At first, you have to download MySql.Data connector dll from http://dev.mysql.com/downloads/connector/net/1.0.html .

Reference the MySql.Data.dll in to your application.

The connection string format will look like this

string conStr = “Server=yourmysqlserver;Port=3309;database=yourdatabasename;userid=username;

password=passwd”;

Sample code follows

using MySql.Data.MySqlClient;

MySqlConnection sqlConn;
MySqlCommand comm;
//    MySqlDataReader reader;

sqlConn = new MySqlConnection(conStr);
sqlConn.Open();

comm = sqlConn.CreateCommand();
comm.CommandText = “UPDATE mytable SET name=’Rami’ WHERE id=1”;

comm.ExecuteNonQuery();

sqlConn.Close();

🙂

Advertisements
Categories: ASP.NET Tags: , ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: