我试图弄清楚我的代码做错了什么(位于下面)。我尝试了几种不同的方法并在线搜索了几种方法,但我似乎无法找出为什么此代码不会将条目添加到我的数据库中。我将 WebMatrix(用于 Web 界面的 cshtml,使用 C#)与 SQL Server Compact 数据库一起使用。我对使用带有数据库的 Web 界面非常陌生。任何帮助深表感谢!
@{
var errorMessage = "";
var POIName = "";
var DateLastModified = "";
var Height = "";
var Weight = "";
var HairColor = "";
var EyeColor = "";
var DOB = "";
var SS = "";
var insertQueryString = "";
if(IsPost)
{
POIName=Request.Form["POIName"];
DateLastModified=Request.Form["DateLastModified"];
Height=Request.Form["Height"];
Weight=Request.Form["Weight"];
HairColor=Request.Form["HairColor"];
EyeColor=Request.Form["EyeColor"];
DOB=Request.Form["DOB"];
SS=Request.Form["SS"];
insertQueryString = "INSERT INTO POITable " +
"(POIName, DateLastModified, Height, Weight, HairColor, EyeColor, DOB, SS) " +
"VALUES (@0, @1, @2, @3, @4, @5, @6, @7)";
var db = Database.Open("PersonsOfInterest");
db.Execute(insertQueryString, POIName, DateLastModified, Height, Weight, HairColor, EyeColor, DOB, SS);
Response.Redirect("~/");
}
}
@RenderPage("~/Shared/HeaderLayout.cshtml")
<div id="FormHolder">
<form action="" method="post">
<table class="formTable">
<tr>
<td class="upperTable">
<span class="oneLine"><label class="upperLabel" for="POIName">POI Name: </label><input type="text" id="POIName" name="POIName" maxlength="50" value=""/></span></br>
<span class="oneLine"><label class="upperLabel" for="DateLastModified">Date Last Modified: </label><input type="text" id="DateLastModified" name="DateLastModified" maxlength="10" value="" /></span></br>
<span class="oneLine"><label class="upperLabel" for="Height">Height: </label><input type="text" id="Height" name="Height" maxlength="5" value="" /></span></br>
<span class="oneLine"><label class="upperLabel" for="Weight">Weight: </label><input type="text" id="Weight" name="Weight" value="" /></span></br>
<span class="oneLine"><label class="upperLabel" for="HairColor">Hair Color: </label><input type="text" id="HairColor" name="EyeColor" maxlength="10" value="" /></span></br>
<span class="oneLine"><label class="upperLabel" for="EyeColor">Eye Color: </label><input type="text" id="EyeColor" name="EyeColor" maxlength="10" value="" /></span></br>
<span class="oneLine"><label class="upperLabel" for="DOB">DOB: </label><input type="text" id="DOB" name="DOB" maxlength="10" value="" /></span></br>
<span class="oneLine"><label class="upperLabel" for="SS">SS#: </label><input type="text" id="SS" name="SS" maxlength="11" value="" /></span></br>
<span class="oneLine"><label class="upperLabel" for="DL">DL#: </label><input type="text" id="DL" name="DL" maxlength="10" value="" /></span></br>
<span class="oneLine"><label class="upperLabel" for="DOC">DOC#: </label><input type="text" id="DOC" name="DOC" maxlength="10" value="" /></span></br>
<span class="oneLine"><label class="upperLabel" for="VehicleTag">Vehicle Tag #: </label><input type="text" id="VehicleTag" name="VehicleTag" maxlength="10" value="" /></span></br>
<span class="oneLine"><label class="upperLabel" for="FBI">FBI#: </label><input type="text" id="FBI" name="FBI" maxlength="10" value="" /></span></br>
<span class="oneLine"><label class="upperLabel" for="Officer">Officer: </label><input type="text" id="Officer" name="Officer" maxlength="50" value="" /></span></br>
<span class="threeLine" style="padding-left: 2px;"><label class="upperLabel" for="AdditionalDescriptors">Additional</br>Descriptors: </label><textarea cols="16" rows="5" id="AdditionalDescriptors" name="AdditionalDescriptors" maxlength="500"></textarea></span></br>
<span class="oneLine"><label class="upperLabel" for="HomePhone">Home Phone</br>Number: </label><input type="text" id="HomePhone" name="HomePhone" maxlength="14" value="" /></span></br>
</td>
<td class="upperTable">
<span class="twoLine" style="padding-left: 2px;"><label class="upperLabel" for="Aliases">Aliases: </label><textarea cols="16" rows="3" id="Aliases" name="Aliases" maxlength="500"></textarea></span></br>
<span class="threeLine" style="padding-left: 2px;"><label class="upperLabel" for="SourceOfInformation">Source of</br>Information: </label><textarea cols="16" rows="5" id="SourceOfInformation" name="SourceOfInformation" maxlength="500"></textarea></span></br>
<span class="threeLine" style="padding-left: 2px;"><label class="upperLabel" for="Address">Address: </label><textarea cols="16" rows="5" id="Address" name="Address" maxlength="500"></textarea></span></br>
<span class="threeLine" style="padding-left: 2px;"><label class="upperLabel" for="AddressInformation">Additional</br>Address</br>Information: </label><textarea cols="16" rows="5" id="AddressInformation" name="AddressInformation" maxlength="500"></textarea></span></br>
<span class="twoLine" style="padding-left: 2px;"><label class="upperLabel" for="KnownAssociates">Known</br>Associates: </label><textarea cols="16" rows="3" id="KnownAssociates" name="KnownAssociates" maxlength="500"></textarea></span></br>
<span class="threeLine" style="padding-left: 2px;"><label class="upperLabel" for="VehicleDescription">Vehicle</br>Description: </label><textarea cols="16" rows="5" id="VehicleDescription" name="VehicleDescription" maxlength="500"></textarea></span></br>
<span class="oneLine"><label class="upperLabel" for="CellPhone">Cell Phone</br>Number: </label><input type="text" id="CellPhone" name="CellPhone" maxlength="14" value="" /></span></br>
</td>
<td class="upperTable">
<span class="mugshot"><label class="upperLabel" for="Mugshot">Mugshot: </label><input type="text" id="Mugshot" name="Mugshot" value="" /></span></br>
<span class="threeLine" style="padding-left: 2px;"><label class="upperLabel" for="Comments">Comments: </label><textarea cols="16" rows="5" id="Comments" name="Comments" maxlength="500"></textarea></span></br>
<span class="oneLine"><label class="upperLabel" for="WorkPhone">Work Phone</br>Number: </label><input type="text" id="WorkPhone" name="WorkPhone" maxlength="14" value="" /></span></br>
</td>
</tr>
</table></br></br>
<span style="font-size: 3em;">________________________________________________</span></br></br>
<span class="oneLine" style="padding-left: 450px;"><label for="WeightedAggregate">Weighted Aggregate: </label><input type="text" id="WeightedAggregate" name="WeightedAggregate" readonly="true" value="0" /></span></br></br>
<table class="formTable">
<tr>
<td>
<ul style="margin-left: -60px;">
<li><span class="oneLineBottom" style="color: #f00"><input type="checkbox" id="WAM1" name="WAM" value="1"/><label for="WAM1"> Admits Membership</label></span></li>
<li><span class="oneLineBottom" style="color: #f00"><input type="checkbox" id="WAM2" name="WAM" value="2"/><label for="WAM2"> Admits Association</label></span></li>
<li><span class="oneLineBottom"><input type="checkbox" id="WAM3" name="WAM" value="3"/><label for="WAM3"> Admits Set Affiliation</label></span></li>
<li><span class="oneLineBottom" style="color: #f00"><input type="checkbox" id="WAM4" name="WAM" value="4"/><label for="WAM4"> Gang Tattoos or Branded</label></span></li>
<li><span class="oneLineBottom"><input type="checkbox" id="WAM5" name="WAM" value="5"/><label for="WAM5"> Gang Clothing or Colors</label></span></li>
</ul>
</td>
<td>
<ul style="margin-left: -215px;">
<li><span class="oneLineBottom"><input type="checkbox" id="WAM6" name="WAM" value="6"/><label for="WAM6"> Hand Signs</label></span></li>
<li><span class="oneLineBottom"><input type="checkbox" id="WAM7" name="WAM" value="7"/><label for="WAM7"> Gang Paraphernalia</label></span></li>
<li><span class="oneLineBottom"><input type="checkbox" id="WAM8" name="WAM" value="8"/><label for="WAM8"> Consistently Observed/FIR's</label></span></li>
<li><span class="oneLineBottom"><input type="checkbox" id="WAM9" name="WAM" value="9"/><label for="WAM9"> Observed with Known Members</label></span></li>
<li><span class="oneLineBottom"><input type="checkbox" id="WAM10" name="WAM" value="10"/><label for="WAM10"> Gang Involved Incidents</label></span></li>
</ul>
</td>
<td>
<ul style="margin-left: -175px;">
<li><span class="oneLineBottom" style="color: #f00"><input type="checkbox" id="WAM11" name="WAM" value="11"/><label for="WAM11"> Identified by Member as a Gang Member</label></span></li>
<li><span class="oneLineBottom" style="color: #f00"><input type="checkbox" id="WAM12" name="WAM" value="12"/><label for="WAM12"> Identified as a Gang Member by Two or More Sources</label></span></li>
<li><span class="oneLineBottom"><input type="checkbox" id="WAM13" name="WAM" value="13"/><label for="WAM13"> In Photo with Confirmed Gang Member</label></span></li>
<li><span class="oneLineBottom"><input type="checkbox" id="WAM14" name="WAM" value="14"/><label for="WAM14"> Named as a Gang Member in Gang Correspondence</label></span></li>
<li><span class="oneLineBottom"><input type="checkbox" id="WAM15" name="WAM" value="15"/><label for="WAM15"> Targeted by Rivals</label></span></li>
</ul>
</td>
<td>
<ul style="margin-left: -40px;">
<li><span class="oneLineBottom"><input type="checkbox" id="WAM16" name="WAM" value="16"/><label for="WAM16"> FIR while Involved in Gang Activity</label></span></li>
<li><span class="oneLineBottom"><input type="checkbox" id="WAM17" name="WAM" value="17"/><label for="WAM17"> Date Arrested for Violent or Weapon Offense</label></span></li>
<li><span class="oneLineBottom"><input type="checkbox" id="WAM18" name="WAM" value="18"/><label for="WAM18"> Felony Criminal History</label></span></li>
<li><span class="oneLineBottom"><input type="checkbox" id="WAM19" name="WAM" value="19"/><label for="WAM19"> Confirmed by Outside Agency</label></span></li>
<li><span class="oneLineBottom"><input type="checkbox" id="WAM20" name="WAM" value="20"/><label for="WAM20"> On Roster Produced by Gang Associates</label></span></li>
</ul>
</td>
</tr>
</table></br></br>
<table class="formTable">
<tr>
<td style="vertical-align: middle; color: #0094ff; padding-left: 20px; padding-right: 70px; width: 500px;">
<span>An individual should be considered for confirmation as a criminal street gang
member when the individual meets the weighted aggregate of at least 20
points and is associated with at least one of the above criteria labeled in red.</span>
</td>
<td style="text-align: center; padding-left: 70px;">
<span style="float: left; height: 120px;"><label>Summarized Incidents Supporting Gang Member Criteria: </label></br>
<textarea style="width: 500px; height: 90px;" id="SummarizedIncidents" name="SummarizedIncidents" maxlength="1000"></textarea></span></br>
</td>
</tr>
</table>
<span style="font-size: 3em;">________________________________________________</span></br></br>
<button type="button" class="btn" onclick="location.href='/IntroPage.cshtml'">Dismiss Entry</button>
<button type="button" class="btn" onclick="location.href=''">Save Entry</button>
</form>
</div>
@RenderPage("~/Shared/FooterLayout.cshtml")
我认为您不需要渲染页面中的代码,但如果需要,我会提供它们(它们只是链接、头部部分和一些常见的结束标签,用于为页面制作未来的页脚)。
当我提交表单时,似乎什么都没有发生(除了重新加载页面),但数据库中没有添加条目。再说一次,你必须原谅我,我是新手,所以如果我遗漏了一些非常明显的东西,我很抱歉,但我根本无法找到解决方案。谢谢!