how to display empty table to datagrid

Answers were Sorted based on User's Feedback



how to display empty table to datagrid..

Answer / dinesh sharma

DataTable tbl=new DataTable;
DataColumn ID=new
Datacolumn("ID",System.Type.GetType("System.Int"));
DataColumn Name=new
DataColumn("NAME",System.Type.GetType("System.String"));
tbl.Columns.add("ID");
tbl.Columns.Add("NAME");
Datarow dr =null;;
for (int i=0;i<100;i++)
{
dr=tbl.NewRow();
}
datagridview1.datasource=tbl;

Is This Answer Correct ?    14 Yes 1 No

how to display empty table to datagrid..

Answer / neha

DataTable tbl=new DataTable();
tbl.Columns.Add("ID", typeof(int));
tbl.Columns.Add("Name");

datagridview.DataSource=tbl;

Is This Answer Correct ?    1 Yes 0 No

how to display empty table to datagrid..

Answer / radhat

This works, but it only provides one empty row.
It doesn't give you 100 empty rows as your code suggests.
To fix this I added:

dr = tbl.Rows.Add();

right underneath the .NewRow(); line

Hope this helps anyone looking for an empty table.

Is This Answer Correct ?    0 Yes 3 No

Post New Answer

More ADO.NET Interview Questions

Why ca not we use multiple inheritance and garbage collector paralelly in .net?

0 Answers  


Whate are different types of Commands available with DataAdapter ?

2 Answers  


What is the difference between Datareader and Dataset?

0 Answers  


can we change the data in dataset? if yes what is the process?

1 Answers   Artech,


What is a dataset?

3 Answers  


What are the several execute methods of ado.net?

0 Answers  


Define data adapter?

0 Answers  


What is ole db and odbc?

0 Answers  


Explain the dataadapter class in ado.net?

0 Answers  


What is data view and variable view?

0 Answers  


Why edit is not possible in repeater?

0 Answers  


Why is stored procedure used in ado.net?

0 Answers  


Categories