What is DataGridView - DataGridView is a View in which we display the details inside a file or also enter it manually using the program.
Code -
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Ex6
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
DataSet Ds = new DataSet();
Ds.DataSetName = "Mark Sheet";
DataTable Dt = new DataTable();
DataColumn Dc1 = new DataColumn("ID");
DataColumn Dc2 = new DataColumn("Name");
DataColumn Dc3 = new DataColumn("Obtained Marks");
DataColumn Dc4 = new DataColumn("Out of Marks");
DataColumn Dc5 = new DataColumn("Percentage");
DataColumn Dc6 = new DataColumn("Grade");
Dt.Columns.Add(Dc1);
Dt.Columns.Add(Dc2);
Dt.Columns.Add(Dc3);
Dt.Columns.Add(Dc4);
Dt.Columns.Add(Dc5);
Dt.Columns.Add(Dc6);
Dt.Rows.Add("01", "Rohan", "585", "600", "90", "First Class");
Dt.Rows.Add("02", "Rahul", "500", "600", "80", "Second Class");
Dt.Rows.Add("03", "Aarti", "525", "600", "83", "Second Class");
Dt.Rows.Add("04", "Aniket", "545", "600", "85", "First Class");
Dt.Rows.Add("05", "Sakshi", "521", "600", "81", "Second Class");
Ds.Tables.Add(Dt);
Ds.WriteXml("MARKSHEET.xml");
}
private void button2_Click(object sender, EventArgs e)
{
DataSet D1 = new DataSet();
D1.ReadXml("MARKSHEET.xml");
dataGridView1.DataSource = D1.Tables[0];
}
}
}
**Important Note - Before running the program, you have to create a Excel file manually with some data in it(eg. ID, Name, Marks, etc).
Then you have to add the file name like this(Ds.WriteXml("MARKSHEET.xml");)
Output -
0 Comments