Description.

These code snippets will demonstrate how to fill a DataGrid manually and with
data from a database. This will involve filling a DataSet using a DataTable and
an ADODataSetCommand. All these classes are very powerful and have many features
that will not be covered here. We will only cover a few of the most simple forms
of population.

Create the DataGrid.

The following steps will create the DataGrid object we will use for the remainder
of the exercise.

Using Visual Studio.NET open a new C# Windows application project.

From the View menu select Toolbox.

Drag a DataGrid onto the form in design mode.

Right click on the DataGrid object on the form and select properties.

Change (Name) to m_dgTest.

See Simple ADO.NET on using namespace
System.Data.OleDb (if using databases)

Displaying database table using OleDbDataAdapter .

This is probably the simplest method. All you need is the database connection
string and SQL select statement to return the table rows. Note that with this
method the columns information is read from the same location as the data. The "SomeName"
parameter is used to label the table in the DataSet as it may contain several
tables. This method also allows for the data to be edited my the user and
changes pushed back into the database using the OleDbDataAdapter .Update()
command.

Fill the DataGrid using DataReader.

If you do not want to write back to the database and want a little more
control over how the data is read or displayed, this section of code should
solve your problem. It opens the DataReader and sets up the columns by reading
the field names from the table. It then iterates through all the table rows
adding them to the DataTable.

Fill the DataGrid from the NT Event Log.

If you became bored enough you may want to create your own event log viewer
or even enable viewing the event log through a aspx page. Here we will fill a
DataSet with the contents of the local machines "Application" event log. The
points to note are;

Note:

How can i fill datagrid with item of differentes tables. I want to do more than one select, and display the result in a datagrid, but now, i can only display items of one element of a table.
Can you help me please.