I get this error on a remote server, but the same code runs fine locally. Please refrain from saying that it sucks, or giving me a sketch of dynamic sql, I did not write it, just trying to understand why it throws an exception. The highlighted error is line 56.
Protected Sub drpDateRange_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles drpRange.SelectedIndexChanged
Dim sql As String = "SELECT postedDate, inspectionType FROM tInspectionRequest WHERE source_lookupID = 'IRS_WEB' "
If _franchiseID > 0 Then sql &= " and franchiseeID = " & _franchiseID.ToString
Dim db As New Database
Dim ds As DataSet = db.selectQuery(sql)
Dim dv As New DataView(ds.Tables(0))
dv.RowFilter = "inspectionType='Buyer' AND postedDate >= #" & DateTime.Now.AddDays(-1) & "#"
lblB1.Text = dv.Count
End Sub
Here is the exception, it seems DateTime.Now.AddDays (-1) doesn't work as a datetime? Regardless of whether this is a release / date issue for a string error, it is strange that it fails only on the remote server and not locally.
The string was not recognized as a valid DateTime. Description: An unhandled exception occurred during the execution of the current web request. Check the stack trace for more information about the error and where it appeared in the code.
Exception Details: System.FormatException: String was not recognized as a valid DateTime.
Source Error:
Line 55: Dim dsInspectionHistory As DataSet = objDB.selectQuery(sqlInspectionHistory)
Line 56: Dim dvInspectionHistory As New DataView(dsInspectionHistory.Tables(0))
Line 57: dvInspectionHistory.RowFilter = "inspectionType='Buyer' AND postedDate >= #" & DateTime.Now.AddDays(-1).ToString & "#"
Line 58: lblB1.Text = dvInspectionHistory.Count
Line 59: dvInspectionHistory.RowFilter = "inspectionType='Seller' AND postedDate >= #" & DateTime.Now.AddDays(-1) & "#"
[FormatException: DateTime.] System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi, DateTimeStyles) +2291962 System.DateTime.Parse(String s, IFormatProvider) +26 System.Data.ConstNode..ctor( DataTable, ValueType, , fParseQuotes) +485 System.Data.ExpressionParser.Parse() +830 System.Data.DataExpression..ctor( DataTable, , ) +124 System.Data.DataView.set_RowFilter ( ) +161 controls_inspectionRequestChart.drpRange_SelectedIndexChanged ( , EventArgs e) xxxx controls_inspectionRequestChart.Page_Load ( , EventArgs e) xxxx System.Web.UI.Control.OnPreRender(EventArgs e) +2117788 System.Web.UI.Control.PreRenderRecursiveInternal() +86 System.Web.UI.Control.PreRenderRecursiveInternal() +170 System.Web.UI.Control.PreRenderRecursiveInternal() +170 System.Web.UI.Control.PreRenderRecursiveInternal() +170 System.Web.UI.Control.PreRenderRecursiveInternal() +170 System.Web.UI.Control.PreRenderRecursiveInternal() +170 System.Web.UI.Control.PreRenderRecursiveInternal() +170 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2041