Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using ASP.NET Calendar 1

Status
Not open for further replies.

ajap99

Programmer
Dec 9, 2004
18
GB
The following SQL returns booking mage on a certain date ie =Date()
I now want to select a date using a calendar.
I have tried populating a textbox and replacing the =Date() with =textbox12.text but it will not work
How could i get this to work

Dim queryString As String = "TRANSFORM First(qyRoomPeriods.BookR) AS FirstOfBookR SELECT qyRoomPeriods.PeriodID FROM qyRoomPeriods WHERE (((qyRoomPeriods.ResourceDates)=Date())) GROUP BY qyRoomPeriods.PeriodID, qyRoomPeriods.ResourceDates PIVOT qyRoomPeriods.ResourceID
 
If you want to use a TextBox to get a date then it will work with:
Code:
Dim strQuery As String = "SELECT FIELD1 FROM MYTABLE WHERE MYDATE = '" & TextBox1.Text & "'"
but remember, depending on what database you are using, you may have to Format the Text so that it is in a date format that the database will recognise. e.g.
Code:
Dim strQuery As String = "SELECT FIELD1 FROM MYTABLE WHERE MYDATE = '" & Format(TextBox1.Text, "dd-MMM-yyyy") & "'"

If you want to do the same thing from a calendar control you would use something like:
Code:
Dim strQuery As String = "SELECT FIELD1 FROM MYTABLE WHERE MYDATE = '" & Calendar1.SelectedDate & "'"


----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
When I enter the date in manually as follows the query will work
WHERE (((qyRoomPeriods.ResourceDates)=#17/01/2005#))

If I put a textbox.text = 17/01/2005

it will not

How can I get the value into the sql in the format #dd/mm/yyyy# from the textbox

what are the # doing ?
 
Just add the # sign into the string e.g.
Code:
Dim strQuery As String = "SELECT FIELD1 FROM MYTABLE WHERE MYDATE = #" & Format(TextBox1.Text, "dd-MMM-yyyy") & "#"

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
I get the following error when I enter this code

BC30205: end of statement expected
 
Try debugging the project, see what SQL Statement is being generated, try running it in you db. If it errors then you have the syntax wrong.

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top