简体   繁体   中英

Insert large asp.net control data row wise into sql table using asp.net c#

Below is my 46 asp.net control including textboxes and dropdownlist to insert data in single button在此处输入图片说明

Below is my asp.net control id as above image given image

ddl_tag1    txt_date1   ddl_type1   txt_narration1   txt_amount1     txt_bill1   txt_fromloc1      txt_tolocation1
ddl_tag2    txt_date2   ddl_type2   txt_narration2   txt_amount2     txt_bill2   txt_fromloc2      txt_tolocation2
ddl_tag3    txt_date3   ddl_type3   txt_narration3   txt_amount3     txt_bill3   txt_fromloc3      txt_tolocation3
ddl_tag4    txt_date4   ddl_type4   txt_narration4   txt_amount4     txt_bill4   txt_fromloc4      txt_tolocation4
ddl_tag5    txt_date5   ddl_type5   txt_narration5   txt_amount5     txt_bill5   txt_fromloc5      txt_tolocation5
ddl_tag6    txt_date6   ddl_type6   txt_narration6   txt_amount6     txt_bill6   txt_fromloc6      txt_tolocation6

below is my table structure the above six row data insert one by one into below format

Sno    TAQ     DATE TYPE   NARRATION   AMOUNT     BILL   FROM LOCATIOM   TO LOCATION

What is the best way to insert data using add button, i have to use for each loop for insertion for above text boxes and drop-down to insertion one row then another row insertion.

If you are manually putting a bunch of controls onto a page, and not databinding them to anything, creating six manual insert statements is pretty much the only option as far as I know.

As one commenter said above, a gridview might be easier, but honestly if the point is solely just to add and not to also display/update (which is what gridviews are best at) I'm not sure how much that would gain you. If the requirement is specifically and only to add six new rows at a time, you're probably doing the easiest thing.

If you ultimately want more functionality than just add records, you may want to take a look at gridview though.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM