I need to insert data through a form using a
datagridview connected to a SQL Server 2008 R2 database. is it ok, if I write a single insert stored procedure query in a while loop in the
closed as unclear what you're asking by MichaelT, gnat, GlenH7, Bart van Ingen Schenau, jwenting May 8 at 10:54
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question.If this question can be reworded to fit the rules in the help center, please edit the question.
In general you want to minimize the number of calls you make from the client to the database. You don't want the client to call the database with every row when you know that you want to add all rows. One way to achieve what you want is to send a group of rows all at one time to the stored procedure. "
This article describes how to use table-valued parameters when calling Stored Procedures. Table-valued parameters were introduced in SQL Server 2008. With this parameter type, a table with several rows can be passed to a Stored Procedure": Send multiple rows to stored procedure.
You need to be careful with validation prior to inserts and perform such an insert in a single transaction otherwise, coding for rows that flailed to insert will require more work.
If your scenario involves file loading into SQL Server, you may want to consider an alternative efficient method such as Bulk Insert.