以下是我的代码:
@{
Layout = "/_SiteLayout.cshtml";
var db = Database.Open("MyDatabase");
var query = "SELECT * FROM Team";
var Teams = db.Query(query);
}
<form>
<table>
<tr>
<td>Team Name</td>
<td>Played</td>
<td>Points</td>
</tr>
@{ foreach(var Team in Teams){
<tr>
<td>@Team.TeamName</td>
<td><input type="text" value="@Team.Played" name="Played"/></td>
<td><input type="text" value="@Team.Points" name="Points"/></td>
</tr>
}
}
</table>
</form>
结果如下:
所以我想做的就是更新我的整个表格。
执行此操作的SQL查询是什么?我希望在发布表单后,为我的数据库中的所有团队更新Points
和Games Played
。
答案 0 :(得分:0)
我实际上并不明白你想要实现的目标(用什么来更新你的整个表格?),但这里有一些你可能会觉得有用的信息:
答案 1 :(得分:0)
以下是我的解决方案。任何人都有一个有效的解决方案?
@ {
var db = Database.Open("MYDATABSE");
var query = "SELECT * FROM Team";
var Teams = db.Query(query);
var InsertQuery = "";
if(IsPost){
foreach(var Team in Teams){
var Points = Request[Team.TeamName];
var TeamId = Team.TeamId.ToString();
var Played = Request[TeamId];
var executeQueryString="UPDATE Team Set Points=@0, Played=@1 WHERE TeamId=@2";
db.Execute(executeQueryString, Points, Played, Team.TeamId);
}
Response.Redirect("~/UpdateTable.cshtml");
}
}
<br /><br />
<form action="" method="post">
<table>
<tr>
<td><h5>Team Name</h5></td>
<td><h5>Played</h5></td>
<td><h5>Points</h5></td>
</tr>
@{ foreach(var Team in Teams){
<tr>
<td>@Team.TeamName</td>
<td><input type="text" value="@Team.Played" name="@Team.TeamId"/></td>
<td><input type="text" value="@Team.Points" name="@Team.TeamName"/></td>
</tr>
}
}