After writing programs for 5 years, you have ever try to look at your first program when you start learning simple programs in Pascal or C++?? I wrote this simple program in the early days of C# and ADO.NET.
In Visual C#, the DataGrid is one of the ToolBox controls. DataGrid can be used to display data from a database by writing only a few lines of code. In this article, I have used a database called "C:\\mcb.mdb" which has a table called 'Student'.
Create a Windows Application and add DataGrid to the Form
Add a DataGrid control to the form and set properties according to your needs.

Adding Source Code
Now you can add this few lines of code anywhere you want to load the data from the database. It may be mouse button click or the Form load event handler.
- private void Form1_Load(object sender, System.EventArgs e) {
- OleDbDataAdapter da = new OleDbDataAdapter("SELECT * FROM Student", "Provider=Microsoft.JET.OLEDB.4.0;data source=C:\\mcb.mdb");
- DataSet ds = new DataSet();
- da.Fill(ds, "Student");
- dataGrid1.DataSource = ds.Tables["Student"].DefaultView;
- }
Simple. I create an OleDb DataAdapter and a DataSet object and call the Fill method of data adapter, which fills the data set. After that, I bind the data set with the DataGrid using the DataSource property. The contents of DataGrid looks like the following figure.

How to Run?
- Download the database zip files and unzip them.
- Add using System.Data.OleDb; namespace in your project. Change the database path in this string. "Provider=Microsoft.JET.OLEDB.4.0;data source=C:\\mcb.mdb");
- Run the application.

Sanjay SrivastavaPosted Oct 13, 2010, 12:20 AM
data in datagrid is not displaying and no error message is given. i need it urgently.
udara samaraweeraPosted Jun 26, 2010, 5:35 AM
how to insert data to the data grid from a vb 6 windows form; pls help thnx in advance
Rehu pandeyeditedPosted May 28, 2010, 12:56 AMEdited May 28, 2010, 12:57 AM
i have connect the database using connect.aspx.cs and retrieving all the data from tables in this files but now i want to display this data using connect.aspx can you tell me me how to do it i am new to asp.net
manoj singhalPosted Feb 16, 2010, 7:53 AM
where is the zip file?
Roshan ErandaPosted Dec 12, 2009, 10:52 AM
Hello I am create Data Grid. This Data Grid form display Tables data. I am add data Data Grid - Choose Data Source - Add project data source my Data Grid Form display data now. my Problem I am add data my access file ( data add) my Data Grid Form not data Refresh. ( program close and next open display data Data Grid) I am need my form button click and data Grid Refresh I am student be so good as to help me.
mishra mishraPosted Nov 12, 2009, 5:58 AM
how to display table in gridview in asp.net
mishra mishraPosted Nov 12, 2009, 5:55 AM
datagridview
sohilshivani sohilshivaniPosted Sep 13, 2009, 2:08 PM
How can I display data in other page using data grid with selective column from the sql server.
isha seharPosted May 31, 2009, 7:52 AM
how we can apply condition on the data which will view in data grid???
hamed ebrahimiPosted May 6, 2009, 4:27 AM
hello how to page "excel" linked to datagride ?
Aminul IslamPosted Jul 12, 2007, 3:03 AM
I need this solution. After clicking column button it will show another DatGridView -- Md. Aminul Islam
kalai vendanPosted Jun 21, 2007, 5:37 AM
i need solution urgently