Tip 6, processing database date values
1099
If a string that contains quotes can cause problems, it is more error-prone for some of our readers to pass date data to the database. Below we explain how to accomplish this task correctly according to the type of database system used.
Ask:
How do I use ASP to pass date data to a database?
For:
The answer is related to the type of database you are using. Suppose we use a variable named "Strdate" to save the date data, and if you use an Access database, the code that generates the string is:
strSQL = "Legitimate SQL command" & "#" & Strdate & "#"
If you are using a database such as SQL Server, Sybase, Oracle, and so on, the code is:
strSQL = "Legitimate SQL command" & "" & Strdate & ""
Note that the difference between the two is the separator used to send date data. Access uses "#", while other databases use single quotes "'".
7. Check that cookies are enabled
User has disabled cookies? It seems that this user does not trust you so much. However, since he is so happy to tricks, you may as well come. Using the method described below, you can check if the user has disabled cookies, and then politely tell him that if you want to use the full functionality of the site, then he must enable cookies.
Ask:
How do I know if the user has turned off cookies?
For:
To check whether the user has turned off the cookie, follow these steps:
Set a cookie.
Redirects the page.
Read the cookie in the redirected page.
If there is a cookie, the user has enabled the cookie, otherwise the user has disabled cookies.
Determine whether you are currently in step 1 or 3 through the query string.
The code example is as follows:
Dim Strcookie, Strtry
Strcookie = Request.Cookies ("MyCookie")
Strtry = Request.QueryString ("Try")
If Strcookie = "" Then
' Check to the If this is a redirect
' After setting the cookie
If strtry = "" Then
Response.Cookies ("MyCookie") = "Set"
' Redirect to this page and try again.
Response.Redirect (Request.ServerVariables ("Script_name")
& "? Try=yes ")
Else
' User/browser didn ' t accept cookies
' Do something ...
End If
Else
'--hooray! User is accepting cookies
'--Delete our cookie:by setting its
'--expiry date to Waaaay
Response.Cookies ("MyCookie"). Expires = "January 1, 1980"
' Do something ...
End If
8, check whether the file exists
If you manage your files through ASP, you must verify that the file exists before you process a file. The simple code described below can be used to verify that a file exists.
Ask:
I want to access the PDF files in a database and create a link to those files in an HTML page. Before refreshing the link, I want to verify that the file does exist. How do I implement Validation in ASP?
For:
In ASP, you can use the FileSystemObject FileExists method to verify that a file exists.
Dim FS, Strfilenameandpath
Strfilenameandpath = Your file name
'--Use file name and path
'--from the database. Remember to map it
'--to the Web Server's point of view.
'--use Server.MapPath to help.
Set fs = CreateObject ("Scripting.FileSystemObject")
If FS. FileExists (Strfilenameandpath) Then
'--File exists
Else
'--file does not exist
End If