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
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.