2012-09-17 121 views
0

我想弄清楚我的代碼出錯(位於下面)。我嘗試了幾種不同的方法,並在網上搜索了幾種方法,但我似乎無法找出爲什麼此代碼不會將條目添加到我的數據庫中。我使用WebMatrix(cshtml作爲Web界面,使用C#)和SQL Server Compact數據庫。我對使用數據庫的Web界面非常陌生。任何幫助深表感謝!用於SQL Server Compact(WebMatrix)的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") 

我不認爲你需要從渲染頁面的代碼,但如果需要的話,我會爲他們提供(它們只是鏈接,頭部,以及用於製造未來頁腳的一些常見的結束標記頁)。

當我提交表單時,沒有看到真正發生(除了重新加載頁面),但數據庫中沒有添加條目。再一次,你必須原諒我,我是新的,所以如果我錯過了一些非常明顯的東西,我很抱歉,但我根本無法找到解決方案。謝謝!

回答

0

好的,請允許我回答我自己的問題,因爲它可能是我可以贖回自己的唯一方式,以便對錯誤進行監督並希望成爲任何可能受益的教訓。

我不敢相信我忽略了這一點,但我在表單的結尾處應用了一個簡單的「按鈕」元素,而不是明顯需要的輸入類型=「提交」按鈕。這當然從未讓表格實際提交。

經驗教訓:無論我們編碼多少次,無論我們做了一百次的任務如何,總會有簡單監督的機會,無論是由疲勞,截止日期,或者只是簡單的自滿。

當所有其他問題都失敗時,請再次閱讀您的代碼,如果您需要的話,請換行,因爲我們都犯了那些花費我們大量時間的簡單錯誤,並且僅僅重新讀取所有代碼有時可能會導致到最快的修復。

感謝任何試圖幫助!

相關問題