0

How to execute a loop in a stored procedure to insert the data in a SQL query?

For demo, I have a gridview in that there is 10 rows of data now that 10 rows of data I want to insert into a table through a stored procedure.

So, as per the logic to insert that 10 rows of data I want to use the loop. Now, the problem that only that how can I use loop of that gridview in the stored procedure.

enter image description here

The screenshot show there are columns:

srno, accountname, cramount, dramount, tdsamt, sgstamt, cgstamt, igstamt

Now, how I will insert this multiple data(as per in image shown) in tmptable through a stored procedure?

Please help me to solve this issues.

Thank you.

9
  • Can you post up some sample data, before, and what you want inserted? You may not need to use a loop. Commented Aug 9, 2017 at 12:03
  • @Leonidas199x I updated the image. Please review it. And I think so for insert the gridview data loop only can use. Is there any other idea then please share it. Commented Aug 9, 2017 at 12:11
  • What language is your gridview in? You should tag that language as that is where you will need to write your loop. Commented Aug 9, 2017 at 12:54
  • I am doing in asp.net with c# Commented Aug 9, 2017 at 12:54
  • Possible duplicate of How to loop through each and every row, column and cells in a GridView and get its value Commented Aug 9, 2017 at 12:57

1 Answer 1

2

As per your need, you can go with bulk insert using XML instead of loop. XML bulk insertion is faster then loop.

All you need to pass your data in XML format to stored procedure. And, Insert that data from XML format, to your table.

You can follow given link, Or you can do google. You will easily get the Solution on google.

1.How to Pass data into XML format; http://www.c-sharpcorner.com/UploadFile/b926a6/insert-multiple-bulk-data-row-in-database-using-xml-in-asp-n/

  1. How to insert data into table from XML format http://www.c-sharpcorner.com/blogs/bulk-insert-into-sql-database-using-xml-file1
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.