Click here to Skip to main content
16,011,685 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi how to insert a record in to dataset without storing it in database and show in grid...now when click on the save button how to store it in database finally
Posted

1 solution

1. Example for adding code in Datatable

DataTable dt = new DataTable();

//Add Datacolumn
DataColumn workCol = dt.Columns.Add("FirstName", typeof(String));

dt.Columns.Add("LastName", typeof(String));
dt.Columns.Add("Blog", typeof(String));
dt.Columns.Add("City", typeof(String));
dt.Columns.Add("Country", typeof(String));

//Add in the datarow
DataRow newRow = dt.NewRow();

newRow["firstname"] = "Arun";
newRow["lastname"] = "Prakash";
newRow["Blog"] = "http://royalarun.blogspot.com/";
newRow["city"] = "Coimbatore";
newRow["country"] = "India";

dt.Rows.Add(newRow);


2. You can store the datatable in Viewstate, and then bind the record in grid, Like wise if any new thing is added add new row in the datatable and update the view state datatable.Then bind in grid,

3. Finally insert all the records using Bulk Insert Datatable into SQL Server using SqlBulkCopy in C#, check below link

http://www.morgantechspace.com/2013/08/bulk-insert-records-into-sql-server.html[^]
 
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