Welcome to Dream.In.Code
Getting Help is Easy!

Join 118,659 Programmers for FREE! Ask your question and get quick answers from experts. There are 863 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! 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
post 23 Jun, 2008 - 10: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

Go to the top of the page


girasquid
post 23 Jun, 2008 - 11:06 AM
Post #2


Barbarbar

Group Icon
Joined: 3 Oct, 2006
Posts: 1,210



Thanked 9 times

Dream Kudos: 650
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

Go to the top of the page

jayman9
post 23 Jun, 2008 - 12:42 PM
Post #3


Student of Life

Group Icon
Joined: 26 Dec, 2005
Posts: 6,473



Thanked 28 times

Dream Kudos: 500

Expert In: C#, VB.NET, Java

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

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 10/12/08 03:56AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month