简体   繁体   English

从多个ASPX网页将数据插入SQL数据库表

[英]Inserting Data into SQL database table from multiple aspx web pages

I am currently have an asp.net web site through visual studio that contains three .aspx pages. 我目前通过Visual Studio有一个asp.net网站,其中包含三个.aspx页面。 Each .aspx page has simple label and text box fields in it. 每个.aspx页中都有简单的标签和文本框字段。 There is a button in each web aspx page also that redirects to the second and third page as well as a submit button at the end of the third page. 每个Web aspx页面中都有一个按钮,它也可以重定向到第二和第三页,第三页面的末尾还有一个提交按钮。 Also behind the buttons there is an sql command/ query that Inserts the input from the textboxes into an sql database. 在按钮后面还有一个sql命令/查询,它将来自文本框的输入插入到sql数据库中。 I have one table in the database that I want input from all three pages. 我在数据库中有一张表,希望从所有三个页面中输入。 When I tried to do this the input from the first page correctly stayed in the first row. 当我尝试执行此操作时,第一页的输入正确地保留在第一行中。 Then the input from the second page made its own second row and so on... I am also using a INSERT statement for each web aspx page. 然后,第二个页面的输入就变成了自己的第二行,依此类推...我还在每个web aspx页面上使用INSERT语句。 I have a picture below of what the database looks like... how can I get all the input into one row 下面是数据库的外观图……如何将所有输入都放入一行

With your current configuration you'll need an update statement instead of an insert statement on the subsequent pages. 使用当前配置,在随后的页面上将需要一个update语句,而不是一个insert语句。

You could also do something like session variables and just insert after you've collected all the information. 您还可以执行类似会话变量的操作,并在收集所有信息之后插入。

If you want to get it into one row, you need to do one INSERT statement and the rest should be UPDATE statements. 如果要将其分成一行,则需要执行一条INSERT语句,其余应为UPDATE语句。 Each and every INSERT statement will create a new row in the database. 每个INSERT语句都会在数据库中创建一个新行。

When trying to UPDATE a row, make sure you add something like WHERE ID = x , so you only update the one row. 尝试UPDATE一行时,请确保添加类似WHERE ID = x ,以便仅更新一行。

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

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