Been staring at this for a while trying to figure out what was wrong with my input string on line 24.
Then it finally dawned on me that the input string that is not correct is the response.redirect that pointed to a folder where the file was not there.
The response redirect is on line 39!
As soon as the file / folder issues was resolved the error message went away.
Can someone see for the information in the stack trace what was going on?
0 : ShowEvents.cshtml - Input string was not in a correct format.
Description:
An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.FormatException: 0 : ShowEvents.cshtml - Input string was not in a correct format.
Source Error:
Line 22: }
Line 23:
Line 24: var row = db.QuerySingle(selectQueryString, EventID); Line 25:
Line 26: var EName = row.EName;
Source File: c:\Users\bb\Documents\My Web Sites\try1\Admin\EventUpdateAdmin.cshtml Line:
24
Stack Trace:
[FormatException: 0 : ShowEvents.cshtml - Input string was not in a correct format.]
System.Data.SqlServerCe.SqlCeCommand.FillParameterDataBindings(Boolean verifyValue) +1184
System.Data.SqlServerCe.SqlCeCommand.ExecuteCommand(CommandBehavior behavior, String method, ResultSetOptions options) +602
System.Data.SqlServerCe.SqlCeCommand.ExecuteDbDataReader(CommandBehavior behavior) +19
System.Data.Common.DbCommand.ExecuteReader() +12
WebMatrix.Data.<QueryInternal>d__0.MoveNext() +157
System.Linq.Enumerable.FirstOrDefault(IEnumerable`1 source) +4232308
WebMatrix.Data.Database.QuerySingle(String commandText, Object[] args) +103
ASP._Page_Admin_EventUpdateAdmin_cshtml.Execute() in c:\Users\bigbird\Documents\My Web Sites\try1\Admin\EventUpdateAdmin.cshtml:24
System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +207
System.Web.WebPages.WebPage.ExecutePageHierarchy(IEnumerable`1 executors) +68
System.Web.WebPages.WebPage.ExecutePageHierarchy() +156
System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +76
System.Web.WebPages.WebPageHttpHandler.ProcessRequestInternal(HttpContextBase httpContext) +119
var db = Database.Open("try1");
var selectQueryString = "SELECT * FROM Events WHERE EventID=@0";
var EventID = UrlData[0];
if (EventID.IsEmpty()) {
Response.Redirect("~/Admin/EventAdmin");
}
var row = db.QuerySingle(selectQueryString, EventID);
var EName = row.EName;
var ELocation = row.ELocation;
var EStart = row.EStart;
var EEnd = row.EEnd;
var EZip = row.EZip;
var EState = row.EState;
var ELink = row.ELink;
var OrganizerID = row.OrganizerID;
if (IsPost && Validation.IsValid())
{
var updateQueryString = "UPDATE Events SET EName=@0, ELocation=@1, EStart=@2, EEnd=@3, EZip=@4, EState=@5, ELink=@6, OrganizerID=@7 WHERE EventID=@8";
db.Execute(updateQueryString, EName, ELocation, EStart, EEnd, EZip, EState, ELink, OrganizerID, EventID);
The error messages and the stack trace both clearly point to the value EventID not being the correct data type for the EventID column in your database. You can see that the exception was raised when SqlServer CE attempted to verify that the parameter value
is the correct data type during its internal FillParameterDataBindings(bool verifyValue) method call.
The error message has nothing to do with the Response.Redirect method call. If you redirect to a file that doesn't exist, you will not get a .NET exception. You get a 404 not found from the web server instead.
EventID is bigint in my table, and the primary key.
var EventID = UrlData[0];
The above statement must then be the root cause of my problem. What is the datatype of the result of UrlData?
Below is the first line of the stack trace. Is your conclusion based on it being the first line in the stack trace or something that you read in this line or any other line?
Below is the first line of the stack trace. Is your conclusion based on it being the first line in the stack trace or something that you read in this line?
EventID is the value that you passed in as a parameter. Whatever it was, it couldn't be converted to whatever data type your database column expected. Hence the exception was raised at that point.
wavemaster
Participant
1279 Points
1124 Posts
Whoa! Input string was not in correct format - WebMatrix really confused on what is going on here
Aug 02, 2012 02:43 AM|LINK
Been staring at this for a while trying to figure out what was wrong with my input string on line 24.
Then it finally dawned on me that the input string that is not correct is the response.redirect that pointed to a folder where the file was not there.
The response redirect is on line 39!
As soon as the file / folder issues was resolved the error message went away.
Can someone see for the information in the stack trace what was going on?
0 : ShowEvents.cshtml - Input string was not in a correct format.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.FormatException: 0 : ShowEvents.cshtml - Input string was not in a correct format.
Source Error:
Line 22: } Line 23: Line 24: var row = db.QuerySingle(selectQueryString, EventID); Line 25: Line 26: var EName = row.EName;Source File: c:\Users\bb\Documents\My Web Sites\try1\Admin\EventUpdateAdmin.cshtml Line: 24
Stack Trace:
var db = Database.Open("try1"); var selectQueryString = "SELECT * FROM Events WHERE EventID=@0"; var EventID = UrlData[0]; if (EventID.IsEmpty()) { Response.Redirect("~/Admin/EventAdmin"); } var row = db.QuerySingle(selectQueryString, EventID); var EName = row.EName; var ELocation = row.ELocation; var EStart = row.EStart; var EEnd = row.EEnd; var EZip = row.EZip; var EState = row.EState; var ELink = row.ELink; var OrganizerID = row.OrganizerID; if (IsPost && Validation.IsValid()) { var updateQueryString = "UPDATE Events SET EName=@0, ELocation=@1, EStart=@2, EEnd=@3, EZip=@4, EState=@5, ELink=@6, OrganizerID=@7 WHERE EventID=@8"; db.Execute(updateQueryString, EName, ELocation, EStart, EEnd, EZip, EState, ELink, OrganizerID, EventID);Mikesdotnett...
All-Star
154818 Points
19853 Posts
Moderator
MVP
Re: Whoa! Input string was not in correct format - WebMatrix really confused on what is going on ...
Aug 02, 2012 04:42 AM|LINK
The error messages and the stack trace both clearly point to the value EventID not being the correct data type for the EventID column in your database. You can see that the exception was raised when SqlServer CE attempted to verify that the parameter value is the correct data type during its internal FillParameterDataBindings(bool verifyValue) method call.
The error message has nothing to do with the Response.Redirect method call. If you redirect to a file that doesn't exist, you will not get a .NET exception. You get a 404 not found from the web server instead.
Beginning ASP.NET Web Pages with WebMatrix | My Site | Twitter
wavemaster
Participant
1279 Points
1124 Posts
Re: Whoa! Input string was not in correct format - WebMatrix really confused on what is going on ...
Aug 02, 2012 12:19 PM|LINK
Should it give an error message when compiling this page?
Mikesdotnett...
All-Star
154818 Points
19853 Posts
Moderator
MVP
Re: Whoa! Input string was not in correct format - WebMatrix really confused on what is going on ...
Aug 02, 2012 12:22 PM|LINK
Are you referring to providing the Response.Redirect method with a string that doesn't refer to an actual page? No.
Beginning ASP.NET Web Pages with WebMatrix | My Site | Twitter
wavemaster
Participant
1279 Points
1124 Posts
Re: Whoa! Input string was not in correct format - WebMatrix really confused on what is going on ...
Aug 02, 2012 12:37 PM|LINK
No to Event ID being the incorrect datatype.
wavemaster
Participant
1279 Points
1124 Posts
Re: Whoa! Input string was not in correct format - WebMatrix really confused on what is going on ...
Aug 02, 2012 01:03 PM|LINK
EventID is bigint in my table, and the primary key.
The above statement must then be the root cause of my problem. What is the datatype of the result of UrlData?
Below is the first line of the stack trace. Is your conclusion based on it being the first line in the stack trace or something that you read in this line or any other line?
GmGregori
Contributor
5418 Points
730 Posts
Re: Whoa! Input string was not in correct format - WebMatrix really confused on what is going on ...
Aug 02, 2012 04:34 PM|LINK
The UrlData type is List<string>.
Look at this good Mike's article: WebMatrix - URLs, UrlData and Routing for SEO.
Mikesdotnett...
All-Star
154818 Points
19853 Posts
Moderator
MVP
Re: Whoa! Input string was not in correct format - WebMatrix really confused on what is going on ...
Aug 02, 2012 07:47 PM|LINK
Yep. That is the point at which the exception was raised.
Beginning ASP.NET Web Pages with WebMatrix | My Site | Twitter
wavemaster
Participant
1279 Points
1124 Posts
Re: Whoa! Input string was not in correct format - WebMatrix really confused on what is going on ...
Aug 02, 2012 07:54 PM|LINK
So, what tells you that it was EventID and not the querystring that was causing the problem?
Mikesdotnett...
All-Star
154818 Points
19853 Posts
Moderator
MVP
Re: Whoa! Input string was not in correct format - WebMatrix really confused on what is going on ...
Aug 03, 2012 03:40 AM|LINK
EventID is the value that you passed in as a parameter. Whatever it was, it couldn't be converted to whatever data type your database column expected. Hence the exception was raised at that point.
Beginning ASP.NET Web Pages with WebMatrix | My Site | Twitter