Welcome to Dream.In.Code
Become an Expert!

Join 150,118 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,964 people online right now. Registration is fast and FREE... Join Now!




String was not recognized as a valid DateTime.

 
Reply to this topicStart new topic

String was not recognized as a valid DateTime.

Gp_V
23 Jun, 2008 - 09:54 AM
Post #1

New D.I.C Head
*

Joined: 17 Jun, 2008
Posts: 2

I have page called default.aspx Where I have link to view report called adddrop.aspx So when I click on report link I should see two dropdown one with startdate and second with enddate. Now When I click on to view link report I am getting error " String Was not recognized as valid DateTime.

Please see the code below for Better idea..


vb


If Len(Request("startDate")) > 0 And Len(Request("endDate")) > 0 Then

SetData(Date.Parse(Request("startDate")), Date.Parse(Request("endDate")))

End If

' Response.Write(Request("startDate"))
' Response.Write(Request("endDate"))


If Not Page.IsPostBack Then
WriteToSiteLog()

End If
End If

End Sub

Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
SetData(CDate(dcStartDate.Value), CDate(dcEndDate.Value))
End Sub

Private Sub ExcelExport_ExcelExport_Click() Handles ExcelExport.ExcelExport_Click
ExcelExport.ExportToExcel(grdResult, Me.lblTitle.Text)
End Sub

#Region "Private Methods"

Private Sub SetData(ByVal startDate As Date, ByVal endDate As Date)

Dim ds As DataSet
Dim sRptType As String

Try
acSum = New wsACSummary.Summary
sRptType = Request("rptType")

'If String.Compare(Request("rptType"), "Added") = 0 Then
If String.Compare(sRptType, "Added") = 0 Then
ds = acSum.GetRegionMemJoined(connString, startDate, endDate)
ds.Tables(0).TableName = "regions"
ds.Tables.Add(acSum.GetMembersJoined(connString, startDate, endDate).Tables(0).Copy)
ds.Tables(1).TableName = "MembersAdded"
ds.Tables.Add(acSum.GetMembersAddedCount(connString, startDate, endDate).Tables(0).Copy)

lblTitle.Text = ds.Tables(1).Rows.Count & " Facilities Added "
lblReason.Text = "Summary of New Patrons"

Else
ds = acSum.GetRegionMemDropped(connString, startDate, endDate)
ds.Tables(0).TableName = "regions"
ds.Tables.Add(acSum.GetMembersDropped(connString, startDate, endDate).Tables(0).Copy)
ds.Tables(1).TableName = "MembersDropped"
ds.Tables.Add(acSum.GetMembersDroppedCount(connString, startDate, endDate).Tables(0).Copy)

lblReason.Text = "Reason for Dropping"
lblTitle.Text = ds.Tables(1).Rows.Count & " Facilities Dropped "

End If

dcStartDate.Value = startDate
dcEndDate.Value = endDate
'dcStartDate.Value = Date.Now
'dcEndDate.Value = Date.Now



dlReasonCount.Visible = True
dlReasonCount.DataSource = ds.Tables(2)
dlReasonCount.DataBind()

ds.Relations.Add("myrelation", ds.Tables(0).Columns("reg_name"), _
ds.Tables(1).Columns("reg_name"))

dlRegions.DataSource = ds
dlRegions.DataBind()

If ds.Tables(2).Rows.Count > 0 Then
lblReason.Visible = True
EnableExportLink(ds, sRptType)
Else
'lblReason.Visible = False
lblReason.Text = "There is no data available for this search"
Me.ExcelExport.btnExport.Visible = False
End If

Catch ex As Exception
Throw ex
End Try

End Sub


Thanks

Mod Edit: Please use code tags when posting your code, like so => code.gif
Thanks,
PsychoCoder smile.gif
User is offlineProfile CardPM
+Quote Post

girasquid
RE: String Was Not Recognized As A Valid DateTime.
23 Jun, 2008 - 10:06 AM
Post #2

Barbarbar
Group Icon

Joined: 3 Oct, 2006
Posts: 1,295



Thanked: 18 times
Dream Kudos: 725
My Contributions
If that's the case, chances are what you're trying to use as a DateTime isn't actually a DateTime - try printing or echoing it somewhere so that you can see what the value is. Alternately, throw a breakpoint onto your code that handles the value, and see what's getting passed in.
User is offlineProfile CardPM
+Quote Post

Jayman
RE: String Was Not Recognized As A Valid DateTime.
23 Jun, 2008 - 11:42 AM
Post #3

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 7,319



Thanked: 66 times
Dream Kudos: 500
Expert In: Everything

My Contributions
Your method is taking a Date object as a parameter, but the DateTimePicker requires a DateTime object. Pass a DateTime object to your method.
CODE

SetData(ByVal startDate As DateTime, ByVal endDate As DateTime)

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 01:17AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month