displaying data in GridView from mysql database using C# asp.net
GridView in C# asp.net using mysql database
Program:-
//heard file
using MySql.Data.MySqlClient;
using System.Data;
// code to connect mysql to gridview
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
string cmdtText = "SELECT * FROM `entry`";
MySqlCommand cmde = new MySqlCommand(cmdtText, connection);
MySqlDataAdapter da = new MySqlDataAdapter(cmde);
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
//close connection
connection.Close();
Output:-
Note:-
* If gridview is not connected to database, it will disappear in browser.
GridView in C# asp.net using mysql database
Program:-
//heard file
using MySql.Data.MySqlClient;
using System.Data;
// code to connect mysql to gridview
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
string cmdtText = "SELECT * FROM `entry`";
MySqlCommand cmde = new MySqlCommand(cmdtText, connection);
MySqlDataAdapter da = new MySqlDataAdapter(cmde);
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
//close connection
connection.Close();
Output:-
Note:-
* If gridview is not connected to database, it will disappear in browser.
Leave reply
Add your comments here