how to display empty table to datagrid
Answers were Sorted based on User's Feedback
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 |
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 |
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 |
How do u implement locking concept for dataset?
What is ado.net architecture?
Explain how to find the given query is optimised one or not?
How do you sort the data in datagrid?
The answers which posted above is not satisfied my requirement? Can some one post teh exact answer? Thanx
What are the different namespaces used in the project to connect the database?
How to add a javaScript function in a datagrid?
OleDbDataAdapter ole=new OleDbDataAdapter(new OleDbCommand ("select * from login",oleDbConnection1)); OleDbCommandBuilder cmd=new OleDbCommandBuilder(ole); ole.Fill(dataSet11,"login"); DataRow drow=dataSet11.Tables ["login"].NewRow(); drow[0]=textBox1.Text; drow[1]=textBox2.Text; drow[2]=textBox3.Text; dataSet11.Tables["login"].Rows.Add (drow); ole.UpdateCommand=cmd.GetUpdateCommand(); ole.Update(dataSet11,"login"); MessageBox.Show("one row added"); this gives exception.how to solve it
How to call the SQL commands asynchronously in ADO.NET version 2.0
Can you explain how to enable and disable connection pooling?
What is difference between executenonquery and executequery?
Which parameter of ConnectionString is used to specify the name of the database?
Visual Basic (800)
C Sharp (3816)
ASP.NET (3180)
VB.NET (461)
COM+ (79)
ADO.NET (717)
IIS (369)
MTS (11)
Crystal Reports (81)
BizTalk (89)
Dot Net (2435)
Exchange Server (362)
SharePoint (720)
WCF (340)
MS Office Microsoft (6963)
LINQ Language-Integrated Query (317)
WPF (371)
TypeScript (144)
Microsoft Related AllOther (311)