Note that there are some explanatory texts on larger screens.

plurals
  1. POInsert multiple sql rows via stored proc
    primarykey
    data
    text
    <p>I have looked a some related topics but my question isn't quite answered:</p> <ul> <li><a href="https://stackoverflow.com/questions/2866235/c-sharp-inserting-multiple-rows-using-a-stored-procedure">C# - Inserting multiple rows using a stored procedure</a></li> <li><a href="https://stackoverflow.com/questions/13540/insert-update-stored-proc-on-sql-server">Insert Update stored proc on SQL Server</a></li> <li><a href="https://stackoverflow.com/questions/3435467/efficient-multiple-sql-insertion">Efficient Multiple SQL insertion</a></li> </ul> <p>I have the following kind of setup when running my stored procedure in the code behind for my web application. The thing is I am now faced with the possibility of inserting multiple products and I would like to do it all in one <code>ExecuteNonQuery</code> rather than do a <code>foreach loop</code> and run it <code>n</code> number of times.</p> <p>I am not sure how to do this, or if it can be, with my current setup. </p> <p>The code should be somewhat self explanatory but if clarification is needed let me know. Thanks.</p> <pre><code>SqlDatabase database = new SqlDatabase(transMangr.ConnectionString); DbCommand commandWrapper = StoredProcedureProvider.GetCommandWrapper(database, "proc_name", useStoredProc); database.AddInParameter(commandWrapper, "@ProductID", DbType.Int32, entity._productID); database.AddInParameter(commandWrapper, "@ProductDesc", DbType.String, entity._desc); ...more parameters... Utility.ExecuteNonQuery(transMangr, commandWrapper); </code></pre> <p>Proc</p> <pre><code>ALTER PROCEDURE [dbo].[Products_Insert] -- Add the parameters for the stored procedure here @ProductID int, @Link varchar(max) @ProductDesc varchar(max) @Date DateTime AS BEGIN SET NOCOUNT ON; INSERT INTO [dbo].[Prodcuts] ( [CategoryID], [Link], [Desc], [Date] ) VALUES ( @ProductID, @Link, @ProductDesc, @Date ) </code></pre> <p>END</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload