Click here to Skip to main content
15,886,795 members
Please Sign up or sign in to vote.
1.80/5 (3 votes)
See more:
How to Write a code for inserting multiple records at a time after clicking submitt button from front end to database using list in c# a

What I have tried:

How to Write a code for inserting multiple records at a time after clicking submitt button from front end to database using list in c# a
Posted
Updated 9-Oct-18 9:25am
Comments
Afzaal Ahmad Zeeshan 15-Oct-16 7:24am    
Why don't submit a bulk object, that contains multiple objects in the form of list?
[no name] 15-Oct-16 7:24am    
"How to Write a code "... how? Well *I* would use a keyboard, that's how. What have you tried? What was the problem with the code you have tried? Iterate through your list and insert the list data to your database.

Well, your first attempt to learn a new thing could have been to search that phrase in Google or Bing. Then with information you get from there you could have tried to write the code according to your requirement. Then if you face any problem, come back here and ask the question with clear description of the problem with code block with the issue.

However, I would suggest to have a look at SqlBulkCopy[^] documentation.

Here are few articles to understand how it can be implemented in real life solutions.
Transferring Data Using SqlBulkCopy[^]
SQL Bulk Copy with C#.Net[^]
Bulk upload into sql server using sqlbulkcopy and C# : www.dotnetmentors.com[^]

Although these articles are written years back but should still work.

Please let me know in case of any difficulties in implementing this if it matches your requirement.

:)
 
Share this answer
 
To add to solution 1: One way could be to define a type for the data and pass several records in a table to a procedure. For an example, have a look at How to pass multiple records to a Stored Procedure[^]
 
Share this answer
 
v2
Comments
Suvendu Shekhar Giri 15-Oct-16 11:02am    
5! :)
Wendelius 16-Oct-16 3:33am    
Thank you :)
Just iterate through all rows and Columns Insert one by One or Else use SQLBulkCopy object in ADO.Net
 
Share this answer
 
Comments
Richard Deeming 11-Oct-18 11:26am    
As already suggested, with more details, in solution 1.

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