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

What is @@rowcount and with small code snippet explain the usage?

4 Answers   BirlaSoft,


Describe ado.net object model in detail.

0 Answers  


Which keyword is used to accept variable number of parameters?

0 Answers  


What are the advantages using ado.net?

0 Answers  


What is ado circle?

0 Answers  






What are all the different methods under sqlcommand?

0 Answers  


How do you find the count of records in a dataset?

0 Answers  


Why do we use sqldataadapter?

0 Answers  


What is microsoft ole db provider for sql server?

0 Answers  


How to enable and disable connection pooling?

0 Answers  


What is the difference between Optimistic and Pessimistic locking?

0 Answers  


what is meant by connection pooling and event pumbling in ado.net

3 Answers   TCS,


Categories