Last post May 04, 2008 07:12 PM by gunteman
May 04, 2008 02:59 PM|aspnetpro9999|LINK
what is wrong with this code
I have a database with a table named sitemembers and BirthDay is a Date/Time field of sitemembers
It gives error in the sql select statement
Dim Username As string
Dim UserExist As Boolean
Dim dt As
dt = Now.Date
DBConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data source=" & Server.MapPath("users.mdb"))
SQLString = "SELECT * FROM [SiteMembers] WHERE [Birthday] = #" & dt &
"# " 'this line causes error
DBCommand = New OleDbCommand(SQLString, DBConnection)
DBReader = DBCommand.ExecuteReader()
If DBReader.HasRows Then
Label1.Text = "Your Username : "
Label1.Text &= DBReader("Username")
username = DBReader("Username")
UserExist = True
Label.Text = "Username Not Found"
UserExist = False
May 04, 2008 04:29 PM|gunteman|LINK
Access (Jet) has its own date function, so this should work.
SELECT * FROM [SiteMembers] WHERE [Birthday] = Date()
May 04, 2008 06:51 PM|aspnetpro9999|LINK
I don't want to get current date
date() should be replaced with a variable so that
dim date1 as date
SQLString = "SELECT * FROM [SiteMembers] WHERE [Birthday] = date1 "
May 04, 2008 07:12 PM|gunteman|LINK
Ah, in that case (and all other cases as well, for that matter), use a parameter
SQLString = "SELECT * FROM [SiteMembers] WHERE [Birthday] = ?"
DBCommand.Parameters.AddWithValue("thedate", date1) ' The name ("thedate") is not relevant. The parameters should be added in the same order as the question marks in the query,