簡體   English   中英

SQL Server Compact(WebMatrix)的Web界面添加數據庫條目不起作用

[英]Web Interface for SQL Server Compact (WebMatrix) adding database entry not working

我試圖找出我的代碼做錯了什么(位於下面)。 我嘗試了幾種不同的方法並在線搜索了幾種方法,但是似乎無法找出為什么這段代碼不會將條目添加到數據庫中。 我在SQL Server Compact數據庫中使用WebMatrix(Web界面使用cshtml,使用C#)。 我對將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")

我認為您不需要渲染頁面中的代碼,但是如果需要,我會提供它們(它們只是鏈接,標頭部分和一些常見的結束標記,可用於將來添加到頁面的頁腳)。

當我提交表單時,什么都沒有發生(除非它重新加載了頁面),但是數據庫中沒有添加的條目。 同樣,您必須原諒我,我是新手,因此,如果我錯過了一些非常明顯的內容,我深表歉意,但我只是無法找到解決方案。 謝謝!

好的,請允許我回答我自己的問題,因為這可能是我可以彌補發生此錯誤所需的監督的唯一方法,並希望能從中汲取教訓。

我不敢相信我忽略了這一點,但是我在表單的末尾應用了一個簡單的“ button”元素,而不是顯然需要的input type =“ submit”按鈕。 當然,這絕對不允許實際提交表單。

經驗教訓:無論我們對代碼進行多少次編碼,無論我們完成一百次任務的等級是多少,一年級總是存在簡單的疏忽的機會,無論是由於疲勞,截止日期還是僅僅是簡單的疏忽造成的自滿。

如果所有其他方法都失敗了,請再次閱讀您的代碼,如果需要的話,請逐行閱讀,因為我們都犯了那些簡單的錯誤,這些錯誤花費了我們大量的時間,而簡單地重新閱讀所有代碼有時可能會導致最快的修復。

感謝所有嘗試提供幫助的人!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM