rtay
asked on
C# multiple inserts into MS SQL DB from single form
I have a user form to plan future loads for delivery in ASP.net / C#. The user pre-enters the delivery loads for the next day. Often, multiple loads are to and from the same location. I am looking for a way for the user to determine how many times the same information from one form entry is entered in to the database.
Example form entries.
LOADID Date PickupLocation Delivery Location Commodity Number of loads
If the user puts the number 10 for number of loads, the entered DATE, PICKUP, DELIVERY AND COMMODITY will be entered into the database in 10 new rows with unique LOADID's
I am not sure where to start looking for the solution to this.
Any help is appreciated.
Example form entries.
LOADID Date PickupLocation Delivery Location Commodity Number of loads
If the user puts the number 10 for number of loads, the entered DATE, PICKUP, DELIVERY AND COMMODITY will be entered into the database in 10 new rows with unique LOADID's
I am not sure where to start looking for the solution to this.
Any help is appreciated.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Line no. 21 to 27 -- I have used a for loop to continuously execute the same command until "Number of Loads"
Maybe a do loop using numberoftimes.text for the x number of times to post?
That sounds a tad painful. Why not add all the rows with a single INSERT statement.
That sounds a tad painful. Why not add all the rows with a single INSERT statement.
If you are using SQL Server 2008, it supports executing multiple INSERT statements as a single query. Here is an example:
INSERT INTO TblLoads (Commodity, PickupLocation, DeliveryLocation, TransDate, NumberOfLoads) VALUES ('Commodity1', 'Location1', '2014-05-01 12:34:00', 3), ('Commodity1', 'Location1', '2014-05-01 12:34:00', 3), ('Commodity1', 'Location1', '2014-05-01 12:34:00', 3);
ASKER
Thank you!
ASKER
Maybe a do loop using numberoftimes.text for the x number of times to post?