Connecting mysql database using c#
Connect mysql to asp.net
Connection between C# and mysql database
Inserting data from C# into mysql
Before connecting C# to mysql we have to install Mysql Connector/Net Download now
Here we using mysql database
Step to add MySql.Data to your project
Step 1:-
Right Click on your project and select Add Reference
Step 2:-
Click on Browse and move to C:\Program Files\MySQL\MySQL Connector Net 6.5.6\Assemblies\v4.0
Note:- Here MySQL Connector Net version is 6.5
Step 3:-
Select MySql.Data.dll file and press ok
Now Write Program for connecting mysql to .net project
Herder file:-
using MySql.Data.MySqlClient;
Program:-
string MyConString = "SERVER=localhost;" +
"DATABASE=speed;" +
"UID=root;" +
"PASSWORD=test;";
/* speed is database name, root is mysql username, test is mysql password */
MySqlConnection connection = new MySqlConnection(MyConString);
MySqlCommand command = connection.CreateCommand()
// open connection
connection.Open();
// entry is mysql table name
//from,to and speedval are column names
string cmdText = "INSERT INTO entry (`from`, `to`, `speedval`) VALUES (@from, @to, @speed )";
MySqlCommand cmd = new MySqlCommand(cmdText, connection);
cmd.Parameters.AddWithValue("@from", Label1.Text);
cmd.Parameters.AddWithValue("@to", Label2.Text);
cmd.Parameters.AddWithValue("@speed", Label3.Text);
cmd.ExecuteNonQuery();
//close connection
connection.Close();
Connect mysql to asp.net
Connection between C# and mysql database
Inserting data from C# into mysql
Before connecting C# to mysql we have to install Mysql Connector/Net Download now
Here we using mysql database
Step to add MySql.Data to your project
Step 1:-
Right Click on your project and select Add Reference
Step 2:-
Click on Browse and move to C:\Program Files\MySQL\MySQL Connector Net 6.5.6\Assemblies\v4.0
Note:- Here MySQL Connector Net version is 6.5
Step 3:-
Select MySql.Data.dll file and press ok
Now Write Program for connecting mysql to .net project
Herder file:-
using MySql.Data.MySqlClient;
Program:-
string MyConString = "SERVER=localhost;" +
"DATABASE=speed;" +
"UID=root;" +
"PASSWORD=test;";
/* speed is database name, root is mysql username, test is mysql password */
MySqlConnection connection = new MySqlConnection(MyConString);
MySqlCommand command = connection.CreateCommand()
// open connection
connection.Open();
// entry is mysql table name
//from,to and speedval are column names
string cmdText = "INSERT INTO entry (`from`, `to`, `speedval`) VALUES (@from, @to, @speed )";
MySqlCommand cmd = new MySqlCommand(cmdText, connection);
cmd.Parameters.AddWithValue("@from", Label1.Text);
cmd.Parameters.AddWithValue("@to", Label2.Text);
cmd.Parameters.AddWithValue("@speed", Label3.Text);
cmd.ExecuteNonQuery();
//close connection
connection.Close();
Thanh you,
ReplyDeleteThis topic is very good and useful.
http://csharp-sqlconnection.blogspot.in/ visit this for easy and short code for database access
ReplyDeleteThis is exactely what I long needed, thank you.
ReplyDeleteThanks for sharing valuable information. Your blogs were helpful to Dot NET learners. I
ReplyDeleterequest to update the blog through step-by-step. Also, find the Dot net news at Dot NET Online Training Bangalore