I created aboutcodes data base having reportcard
table as show below
Now go to aspx page and create GridView as show
below
For customize GraidView make AutoGenerateColumns to
False and DataField
Must be same
as column name of reportcard table
Now go to aspx.cs page and create a function called
reportdisplay
Click here to make connection between mysql and
asp.net
private void reportdisplay()
{
string MyConString = "SERVER=localhost;" +
"DATABASE=aboutcodes;" +
"UID=root;" +
"PASSWORD=;";
using
(MySqlConnection connection = new MySqlConnection(MyConString))
{
try
{
connection.Open();
string cmdtText = "SELECT * FROM `reportcard`";
//string cmdtText = "SELECT `idnumber`,`student`,`subject`,`markes`
FROM `reportcard`";
MySqlCommand cmde = new MySqlCommand(cmdtText, connection);
MySqlDataAdapter da = new MySqlDataAdapter(cmde);
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
connection.Close();
}//end of try
catch (Exception)
{
Label1.Text= "Error In Connection";
}//end of catch
}//end of use
}// end
of reportdisplay function
Call reportdisplay function in Page_Load function
You also can use below statement
string cmdtText = "SELECT * FROM
`reportcard`";
For below code you can use same reportdisplay
function that’s means DataField is very important for GridView
The table looks like this
Leave reply
Add your comments here