Click here to Skip to main content
15,881,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear i am getting error when running code from IIS. When i run from code it runs fine but when i triy it with IIS server i get error:
THis is the error i m getting.


Server Error in '/' Application.

String was not recognized as a valid DateTime.

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: String was not recognized as a valid DateTime.

Source Error:


Line 141:        value = Request.Form("datepicker")
Line 142:        value2 = Request.Form("datepicker2")
Line 143:        moh = valq.caseExp1(value, value2, CompanyId, CName, AID, AName, ASID, ASName, cnn, 1, 3, DropDownList1.SelectedValue)
Line 144:
Line 145:    End Sub


Source File:
C:\inetpub\ftproot\WebSiteMohinder_Final_latest\CashierwiseReports.aspx.vb 
   Line: 143 


Stack Trace:

[FormatException: String was not recognized as a valid DateTime.]
   System.DateTime.Parse(String s) +6363426
   IBillCloudExp.Class1.Expdt2(String cnn, String sp, String para1, String para2, String filename, String comp, String CName, String Area, String AName, String SArea, String SAName, Int32 UserId) in C:\Users\Trucount\Desktop\IBillCloudExp\IBillExp\Class1.vb:579
   IBillCloudExp.Class1.caseExp1(String date1, String date2, String comp, String Cname, String Area, String AName, String SubArea, String SAName, String cnn, Int32 repno, Int32 Srepno, Int32 UserID) in C:\Users\Trucount\Desktop\IBillCloudExp\IBillExp\Class1.vb:1013
   CashierwiseReports.Button1_Click(Object sender, EventArgs e) in C:\inetpub\ftproot\WebSiteMohinder_Final_latest\CashierwiseReports.aspx.vb:143
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +154
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3707

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1025



Please help me out.

Regards,
Venga
Posted
Updated 23-Feb-15 21:51pm
v2
Comments
stibee 24-Feb-15 1:58am    
Can you show some code like CashierwiseReports.aspx.vb Line: 143
mvengaqua 24-Feb-15 2:11am    
Dim valq As New IBillCloudExp.Class1
Dim conAC As New AllFunction
conAC.Check()
conAC.Constr.Open()
Dim sqlcmd As New SqlCommand()
sqlcmd.Connection = conAC.Constr
Dim cnn As String = "Password=micromation;Persist Security Info=True;User ID=sa;Initial Catalog=IBillCloud;Data Source=TRUCOUNT-PC"
Dim moh As String
Dim value, value2 As String
value = Request.Form("datepicker")
value2 = Request.Form("datepicker2")
moh = valq.caseExp1(value, value2, CompanyId, CName, AID, AName, ASID, ASName, cnn, 1, 3, DropDownList1.SelectedValue)
manak chand 24-Feb-15 2:37am    
can you show code for this method .. valq.caseExp1(par1, par2)..
I need to see the conversion from string to date,,i.e value and value2 to date...
mvengaqua 24-Feb-15 3:18am    
Public Function caseExp1(ByVal date1 As Date, ByVal date2 As Date, ByVal comp As String, ByVal Cname As String, ByVal Area As String, ByVal AName As String, ByVal SubArea As String, ByVal SAName As String, ByVal cnn As String, ByVal repno As Integer, ByVal Srepno As Integer, ByVal UserID As Integer)
Dim sp, FN As String
Select Case repno
Case Is = 1
If Srepno = 3 Then
sp = "Cashierwise_Report2"
FN = "CahierWise"
'moh = valq.Expdt(cnn, st, "BillMaster_1.Date", DateTimePicker1.Value.ToShortDateString, DateTimePicker2.Value.ToShortDateString, FN, "", "", "")
Expdt2(cnn, sp, date1, date2, FN, comp, Cname, Area, AName, SubArea, SAName, UserID)
End If
End Select

End Function



Public Function Expdt2(ByVal cnn As String, ByVal sp As String, ByVal para1 As String, ByVal para2 As String, ByVal filename As String, ByVal comp As String, ByVal CName As String, ByVal Area As String, ByVal AName As String, ByVal SArea As String, ByVal SAName As String, ByVal UserId As Integer)
'Dim con_str As String = cnn '"Data Source=.\SQLEXPRESS;AttachDbFilename=D:\Code IBILL\IBIll Touch 2.0\IBill1.0\bin\Debug\DBRestro.mdf;Integrated Security=True;User Instance=True"
'Dim Xlapp As New Microsoft.Office.Interop.Excel.Application
Dim sqlcon As New SqlConnection(cnn)
Dim sqlcmd4 As New SqlCommand()
sqlcmd4.Connection = sqlcon
Dim nameA As String = ""
If comp <> "" And Area <> "" And SArea <> "" Then

sqlcmd4.CommandType = CommandType.StoredProcedure
sqlcmd4.CommandText = sp
sqlcmd4.Parameters.AddWithValue("@CompanyID", comp)
sqlcmd4.Parameters.AddWithValue("@UserID", UserId)
sqlcmd4.Parameters.AddWithValue("@AreaCodeID", Area)
sqlcmd4.Parameters.AddWithValue("@AreaCodeSubID", SArea)
sqlcmd4.Parameters.AddWithValue("@FDate", SqlDbType.Date).Value = Date.Parse(para1)
sqlcmd4.Parameters.AddWithValue("@ToDate", SqlDbType.Date).Value = Date.Parse(para2)
'sqlcmd.CommandText = "select " + field + " where (" + datefilter + ") and " + sec + " "
Dim sqldap4 As New SqlDataAdapter(sqlcmd4)
Dim dst4 As New DataSet()
sqldap4.Fill(dst4, "tab")
Dim dt4 As DataTable = dst4.Tables("tab")
If dt4.Rows.Count > 0 Then
Dim name4 As String
name4 = filename + "_" + CName + "_" + nameA + "_" + SAName + "_" + Now.Date + ".xls"
GenerateXls(name4, dt4)
'Else
' MsgBox("No Record to Export", MsgBoxStyle.OkOnly)
End If
End If

End Function

This kind of error can also occur if your server datetime is not in the format as your format you code for date. Set the datetime of the server machine i think it will work.
 
Share this answer
 
Hi.. you need to convert value and value to date before passing same to Valq.caseExp1 Function... I think that might be causing issue
 
Share this answer
 
Comments
mvengaqua 24-Feb-15 4:01am    
but this is working fine when i am runing from code. But it gives this error when i run through IIS.
manak chand 24-Feb-15 4:20am    
This must be issue with date format.. pls set the date format like this..
DateValue.ToString('dd/MMM/yyyy')
mvengaqua 24-Feb-15 4:49am    
where should i set this. please tell me
manak chand 24-Feb-15 4:56am    
DateTime value = Convert.ToDateTime(Request.Form("datepicker")).ToString('dd/MMM/yyyy')
DateTime value2 = Convert.ToDateTime(Request.Form("datepicker2")).ToString('dd/MMM/yyyy')
moh = valq.caseExp1(value, value2, CompanyId, CName, AID, AName, ASID, ASName, cnn, 1, 3, DropDownList1.SelectedValue)
mvengaqua 24-Feb-15 5:48am    
Dim value, value2 As String
value = Convert.ToDateTime(Request.Form("datepicker")).ToString('dd/MMM/yyyy')
value2 = Convert.ToDateTime(Request.Form("datepicker2")).ToString('dd/MMM/yyyy')



this is not correct

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900