C# 基于循环更改参数值
如何根据html表是否可见来循环它们,并为每个循环分配不同的参数值。不确定这是否是正确的方法,但如果可能的话,我希望得到一些建议和一些如何完成以下任务的示例代码 表格示例C# 基于循环更改参数值,c#,asp.net,sql-server,tsql,C#,Asp.net,Sql Server,Tsql,如何根据html表是否可见来循环它们,并为每个循环分配不同的参数值。不确定这是否是正确的方法,但如果可能的话,我希望得到一些建议和一些如何完成以下任务的示例代码 表格示例 Four of these tables so for the second table I have the id="txtLName1" <table id="tblEvent1" class="tblAttendee"> <tr>
Four of these tables so for the second table I have the id="txtLName1"
<table id="tblEvent1" class="tblAttendee">
<tr>
<td>Last Name:</td>
<td><input id="txtLName" runat="server" type="text" name="name" /></td>
</tr>
<tr>
<td>First Name:</td>
<td><input id="txtFName" runat="server" type="text" name="name" /></td>
</tr>
<tr>
<td>Gender:</td>
<td><asp:DropDownList ID="ddlGender" runat="server" Width="65%">
</asp:DropDownList></td>
</tr>
<tr>
<td>Age:</td>
<td><asp:DropDownList ID="ddlAge" runat="server" Width="65%">
</asp:DropDownList></td>
</tr>
<tr>
<td>Comments:</td>
<td><textarea id="txtComments" runat="server" type="text"></textarea></td>
</tr>
</table>
Table1 - visible = true
Table2 - visible = true
Table3 - visible = true
Table4 - visible = false
using (SqlConnection con = new SqlConnection(connectionString))
{
using (SqlCommand cmd = con.CreateCommand())
{
cmd.CommandText = "StoredProcedureName";
cmd.CommandType = CommandType.StoredProcedure;
Loop through tables where visible = true
//first loop
cmd.Parameters.AddWithValue("@LastName", Request.Form["(Table1.LastName"]);
insert new record to database
//second loop
cmd.Parameters.AddWithValue("@LastName", Request.Form["Table2.LastName"]);
insert new record to database using same storedprocedure call
//third loop
cmd.Parameters.AddWithValue("@LastName", Request.Form["Table3.LastName"]);
insert new record to database using same storedprocedure call
No 4th loop because Table is not visible.
将sql存储过程更改为接受所有参数,但仅在参数不为null时插入到表中您使用的是web窗体还是mvc?页面上的代码是什么样子的?表是如何填充的?我添加了一个表TomT的示例,这是webforms asp.net C,sql表将根据列出的字段填充。也许我问得不够清楚,但我正试图通过将第一个表插入数据库,然后循环将第二个表作为新记录插入,从而根据我的网页循环中可见的表的数量来确定
(LastName)Smith (firstName)Bob (gender)Male (age)13 (linkid)1
(LastName)Smith (firstName)Timmy (gender)Male (age)7 (linkid)1
(LastName)Smith (firstName)Jenny (gender)Female (age)9 (linkid)1