2014-02-09 42 views
0

代碼:輸入字符串格式不正確var row = db.QuerySingle(sqlSelect,id);

@{ 
var id = UrlData[0]; 
if (id.IsEmpty()){ 
    Response.Redirect(@Href("~/surveydata")); 
} 

var db = Database.Open("StarterSite"); 

if (IsPost){ 
    var sqlDelete = "DELETE FROM PatientSurvey WHERE [email protected]"; 
    db.Execute(sqlDelete, id); 
    Response.Redirect("~/surveydata"); 
} 

var sqlSelect = "SELECT * FROM PatientSurvey WHERE [email protected]"; 
var row = db.QuerySingle(sqlSelect, id); 
} 

<p>Are we sure we want to delete the following record? @id</p> 
<p> 
<form action="" method="post"> 
    <input type="button" onclick="document.location.href='surveydata.cshtml';" value="Cancel" /> 
    <input type="submit" value="Delete" /> 
</form> 
</p> 

線:

第18行:VAR的SQLSelect = 「SELECT * FROM PatientSurvey WHERE ID = @ 0」;
第19行:var row = db.QuerySingle(sqlSelect,id);

堆棧跟蹤:
[出現FormatException:0:surveydata.cshtml - 輸入字符串的不正確的格式。]
System.Data.SqlServerCe.SqlCeCommand.FillParameterDataBindings(布爾verifyValue)1244
System.Data .SqlServerCe.SqlCeCommand.ExecuteCommand(的CommandBehavior行爲,字符串方法,ResultSetOptions選項)569
System.Data.SqlServerCe.SqlCeCommand.ExecuteDbDataReader(的CommandBehavior行爲)19
System.Data.Common.DbCommand.ExecuteReader()12
WebMatrix.Data.d__0.MoveNext()+152
System.Linq.Enumerable.FirstOrDefault(IEnumerable的1 source) +164
WebMatrix.Data.Database.QuerySingle(String commandText, Object[] args) +103
ASP._Page_delete_cshtml.Execute() in c:\Users\Matt\Documents\My Web Sites\Scott New PTSSM\delete.cshtml:19
System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +197
System.Web.WebPages.WebPage.ExecutePageHierarchy(IEnumerable
1執行人)69
System.Web.WebPages.WebPage.ExecutePageHierarchy()151
System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext中,TextWriter的作家,WebPageRenderingBase起始頁)+76
System.Web.WebPages.WebPageHttpHandler.ProcessRequestInternal(HttpContextBase的HttpContext)+114

回答

0

我想你需要留有空格,像這樣:

var sqlSelect = "SELECT * FROM PatientSurvey WHERE ID = @0"; 

乾杯