简体   繁体   English

使用 asp.net c# 将大的 asp.net 控件数据按行插入 sql 表

[英]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下面是我的 46 个 asp.net 控件,包括文本框和下拉列表,用于在单个按钮中插入数据在此处输入图片说明

Below is my asp.net control id as above image given image下面是我的 asp.net 控件 ID,如上图所示

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.正如上面的一位评论者所说,gridview 可能更容易,但老实说,如果重点只是添加而不是显示/更新(这是 gridviews 最擅长的),我不确定这会给你带来多少。 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.如果您最终想要更多的功能而不仅仅是添加记录,您可能需要查看 gridview。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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