Click here to Skip to main content
15,881,173 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
how to add the data in dataset one by one when clicked button event. Then i want to bind dataset to gridview for dispaly those data in c#.net . Need example program in c#.net
Posted

Hi,
Please find the code snippet for adding data to a dataset. Logic and No of columns in table/dataset can vary but the syntax remains same
C#
DataSet ds = new DataSet();
DataTable dt = new System.Data.DataTable();
dt.Columns.Add("EmpName");
dt.Columns.Add("Dept");

DataRow dr = dt.NewRow();
dr["EmpName"] = txtName.Text;
dr["Dept"] = txtDept.Text;

dt.Rows.Add(dr);
ds.Tables.Add(dt);

DataGrid dg = new DataGrid();
dg.DataSource =dt;
gpDisplayGrid.Controls.Add(dg);

Hope it helps.
Regards, Mahe
 
Share this answer
 
I think you are new to the programming in C#,
Please refer the following links
http://www.homeandlearn.co.uk/csharp/csharp_s12p9.html[^]
http://www.dotnetperls.com/dataset[^]
http://www.csharptuts.net/dataset-in-c/[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900