Monday, July 21, 2008

How to bind a DataSet to a DataGridView, a DataGrid?

A DataSet is memory resident data in DataTables in the DataTables collection. Each table is known by its name.

Let us say a DataTable named "MyTable" in a DataSet called "MyDs" needs to be bound to a DataGrid or a DataGridView controls. Then the following code does this binding:

DataGridView1.DataSource=MyDs.Tables("MyTable")




and for a Datagrid it will be,

DataGrid1.SetDataBinding(MyDs,"MyTable")

2 comments:

tiberiumihai said...

thanks man.
just what I was looking for.

... said...

thanks .... read a lot of instruction etc... all of them complicates matter and makes me confuse.

yours is truly exceptional