Session Variable to SQL Parameter

Hello,
In ASP.NET 2.0
I have a date value saved as a Session variable
ie:
Dim dtToday As DateTime = DateTime.Today
Session("dtCurr") = dtToday.ToString

Then trying to get that value into a Select Statement
ie:
SelectCommand = "SELECT [EventTitle], [EventStartDate], [EventStartTime], [EventEndTime] From [Events] Where ([EventStartDate]) = CONVERT(datetime,@EventStartDate)"

<SelectParameters>
<asp:Parameter DefaultValue="Session(&quot;dtCurr;&quot;)" Name="EventStartDate" Type="String" />
</SelectParameters>
...
Getting a syntax error: converting datetime from character string. Have tried a number of permutations, but to no avail.
LVL 1
el_scottyAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

matthewrhoadesCommented:
Is there a reason you used the type "String" as opposed to type "DateTime".  It might help you to cut the two conversions out of the picture (1 conversion being storing a date as a string, 2 being the conversion back to DateTime)
0
el_scottyAuthor Commented:
Well that was left from one permutation - I just changed it back to:
Session("dtCurr") = dtToday

Select Statement to: "Where ([EventStartDate]) = @EventStartDate"

and

Parameter value to: Type='DateTime'

But Still getting System.FormatException:
String Not recognized as a Valid dateTime. unknown word at index 0

0
matthewrhoadesCommented:
If it is set up with Try ... Catch... End Try...  you should catch the exception and message box the value of the variable so you can see the format of the date string.  Either way it would be best to see what that variable looks like when it throws the error, it may be simple when you see it.  IF you can get the value that @EventStartDate throws, post it.  You may need to reorder it (I think there some native date formatting functions you can use)
0
samtran0331Commented:
Your code here:
<SelectParameters>
<asp:Parameter DefaultValue="Session(&quot;dtCurr;&quot;)" Name="EventStartDate" Type="String" />
</SelectParameters>

The value is literally the text: Session("dtCurr")
(Not the value of the session, but that actual text as above)...

Try using a session parameter:
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.sessionparameter.aspx
(scroll down to see the example)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
el_scottyAuthor Commented:
Thank You.
SessionParameter does the trick.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.