0
我想寫一個代碼在VS2012我可以鍵入用戶名,勾選表中的項目複選框,並提交。然後它會將每個項目的用戶名插入數據庫表中。我嘗試做這樣的事情,但它不會插入。添加多行到數據庫表剃鬚刀CSHTML
我想將新行添加到名爲SectionAccess的表中。因此,如果一個ID「group1」分別檢查3個項目(帶有鏈接1,2,3),它將在表中插入3行('group1','1'),('group1','2'), ( '組1', '3')。
@{
Layout = "~/_SiteLayout.cshtml";
Page.Title = "Admin Console";
var db = Database.Open("Testreporting");
var sql_c = "select Link, PPMID, EPRID, Proj_Name from AdminConsole;";
var addgroup = "insert into SectionAccess (Access, UserID, Link) values ('user', '" + Request["UserID"] + "','" + Request["add"] + "');";
var temp = "";
var Link = "";
var r_group = Request["UserID"];
int counter = 0;
if (!Request.Params["add"].IsEmpty())
{
foreach(var row in db.Query(sql_c)){
if (Request["add"+Link]=="True")
{
db.Execute(addgroup);
}
}
}
}
<form name ="NewGroup" method="get" >
<fieldset>
<legend>Add New Group</legend>
<h6>Step 1:</h6>
<label for ="NewGroupID">Enter New Group ID: </label>
<input type="text" name= "UserID" value="@Request.Form["UserID"]" />
<h6>Step 2:</h6>
<p>Add Desired Project: </p>
<table>
<tr>
<th >#</th>
<th >PPMID</th>
<th >EPRID</th>
<th >Project Name</th>
<th >Add</th>
</tr>
@foreach (var row in db.Query(sql_c)) {
counter++;
<tr class="@temp">
<td><br />
@row.Link
</td>
<td><br />
@row.PPMID
</td>
<td ><br />
@row.EPRID
</td>
<td ><br />
@row.Proj_Name
</td>
<td><br /><input type="checkbox" id="checkbox" name="[email protected](row.Link)" value="@row.Link"/></td>
</tr>
}
</table>
<br /><input style="float:right;font-weight:bold" type="submit" onclick="return confirm('Are you sure you want to add?')" id="add" name="[email protected](Link)" value="@Link"/>Add Project<br />
<div class = "home">
<br /><a href="@Href("~/AdminConsoleHome.cshtml")">Back to Homepage</a>
</div>
</fieldset>
</form>
我在做什麼錯在這裏?
在'
您試圖創建SPA(單頁)還是MVC視圖頁?我看到'' is WebForms way to point a physical aspx page, MVC should use 'Back to Homepage'。 –
參數化您的查詢。 –