Link to home
Start Free TrialLog in
Avatar of Marty_O
Marty_OFlag for Canada

asked on

How to retreive a date from a hidden value with an SqlDataSource in ASP.NET (VB.NET)

Hi
I am trying to run a query based on the date at which the user visits the page that will populate a datagrid. The datagrid populates through an SqlDataSource preconfigured with the code found in the code window.

Database : SQL2005 latest release
Web page : VB.NET ==> ASPX (pro 2008 edition)

The query uses parameters : @DateReturn and @UID
Parameter Sources : Controls on the webform (Hidden Value fields)

The @DateReturn parameter of the sqlDataSource is mapped to a hidden control on the page  that is set at the PageLoad event to the Date.Now value. I also tried formatting the date with the "#" , and also tried using Date.Today.

@UID gets its value from another hidden value set at the at the PageLoad event as well.

In debugging, both values are correctly there and accessible by code.

When the sqlDataSource.Databind gets fired, I get an arithmatic error caused by an overflow in the @DateReturn field.

The field to compare the date IS a datetime datatype.

SqlDataSource Select Statement :
 
SELECT * FROM tblStock
WHERE fldDateReturn > @DateReturn 
AND
fldUserID = @UID
 
'PageLoad Event
me.dateVal.value = date.now
me.uidVal.value = userid  ' retrieved trough another sub

Open in new window

Avatar of jinal
jinal
Flag of India image

SELECT * FROM tblStock
WHERE fldDateReturn > '@DateReturn'
AND
fldUserID = @UID
Try to give defalut value in <asp:ControlParameter  ..
of Sql DataSource . Error indicate that date is not supplied.
 
ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
In above comment just update connection string and test.
Avatar of Marty_O

ASKER

Thanks for the input. By reading both solutions, I realized I had missed a crutial step... specify in the control properties that the type of data was a datetime for my hidden value. Since both solutions worked, I awarded equal points. Thanks again!