在查詢另一個頁面上的條目的值時,剛剛將其插入數據庫後,我收到錯誤消息。錯誤如下:使用帶Webmatrix的QueryValue獲取commandText值不能爲空或空
Value cannot be null or an empty string.
Parameter name: commandText
堆棧跟蹤看起來是這樣的(如果不知道這會有所幫助):
[ArgumentException: Value cannot be null or an empty string.
Parameter name: commandText]
WebMatrix.Data.Database.QueryValue(String commandText, Object[] args) +20791
ASP._Page_EntryViewer_cshtml.Execute() in c:\Users\administrator.OKMCITY\Documents\My Web Sites\Persons Of Interest\EntryViewer.cshtml:101
System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +197
System.Web.WebPages.WebPage.ExecutePageHierarchy(IEnumerable`1 executors) +69
System.Web.WebPages.WebPage.ExecutePageHierarchy() +151
System.Web.WebPages.StartPage.RunPage() +17
System.Web.WebPages.StartPage.ExecutePageHierarchy() +62
System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +76
System.Web.WebPages.WebPageHttpHandler.ProcessRequestInternal(HttpContextBase httpContext) +114
線發生在錯誤(行101):
Line 99: var db = Database.Open("PersonsOfInterest");
Line 100:
Line 101: var activeID = db.QueryValue((string)Session["activeEntrySelectQueryString"], (string)Session["gPOIName"], (string)Session["gDateLastModified"], (string)Session["gGender"], (string)Session["gRace"], (string)Session["gHeight"], (string)Session["gWeight"], (string)Session["gHairColor"], (string)Session["gEyeColor"], (string)Session["gDOB"], (string)Session["gAge"], (string)Session["gSS"], (string)Session["gDL"], (string)Session["gDOC"], (string)Session["gVehicleTag"], (string)Session["gFBI"], (string)Session["gOfficer"], (string)Session["gAdditionalDescriptors"], (string)Session["gHomePhone"], (string)Session["gAliases"], (string)Session["gSourceOfInformation"], (string)Session["gAddress"], (string)Session["gAddressInformation"], (string)Session["gKnownAssociates"], (string)Session["gVehicleDescription"], (string)Session["gCellPhone"], (string)Session["gCellPhone2"], (string)Session["gCellPhone3"], (string)Session["gPOICautions"], (string)Session["gComments"], (string)Session["gWorkPhone"], (string)Session["gSummarizedIncidents"], (string)Session["gPOILastName"]);
Line 102: Session["gEntryID"] = activeID;
Line 103:
我似乎無法找到此錯誤的原因,因爲它發生在用戶「保存」他之後/她進入數據庫,但發生了一些雜亂的,看似隨意的事情。頁面嘗試查詢該條目唯一主鍵的值。存儲在上面看到的會話變量中的值是根據以前用於將新條目插入到數據庫中的值存儲的(我必須這樣做,因爲主鍵「是身份」,並且該值會隨着每個值自動遞增條目增加)。
可能有更好的(更簡單)的方法來做我想做的事情,但我認爲這樣做會比僅僅在主鍵上使用MAX(集合函數)更加一致。
在這個問題上我可能會提供更多的信息,但是我真的不想用不必要的信息填充這個頁面(如果我還沒有的話)。只要告訴我是否還有其他事情可以提供。
一些更多的說明:
的「會話[‘gDateLastModified’]」是從被使用JavaScript自動繪製的窗體上的一個字段抓住,所以這個值(精確到秒)應(就像這個查詢中的所有其他變量)匹配剛剛輸入到數據庫中的值(是的,我相信用戶的JavaScript已啓用並且功能正常)。
此外,它可能很明顯,但第101行的QueryValue命令具有第一個參數作爲select查詢字符串,當然使用參數化查詢,而其餘參數是必須匹配以檢索行數據庫。
記住這個錯誤只會偶爾發生。
如果我添加了太多的信息(或者遺漏了某些信息),我真的很抱歉,但是我不知道從哪裏開始認識到這個問題可能存在,所以不確定所有人都可以幫助誰試圖幫我。只要告訴我是否還有其他事情可以提供。
UPDATE
我只知道現在是一個字符串故意只要填寫因爲它是IsPost',那麼該字符串用來直接填寫相關的會話變量。我知道會話變量實際上是cookie,但非常肯定的是沒有人會手動清除它們(並且在點擊提交按鈕之後並且在下一頁加載之前,在此過程的中間的某個地方)他們必須這樣做,還有什麼可能導致這個值被清除?我假設commandText是在db.QueryValue期間傳遞我的查詢字符串的值的變量,這是正確的嗎?
我編輯了你的標題。請參閱:「[應該在其標題中包含」標籤「](http://meta.stackexchange.com/questions/19190/)」,其中的共識是「不,他們不應該」。 –
@John Saunders謝謝 – VoidKing