I have a problem finding solution to my problem. I am making a database application which inserts time and date data into the database. I did try several ways but i opt lastly on converting it into strings data type,likewise also i did to the datatype in the Access database.
I have this code below,this is where the problem occurs:
++++++++++++++++++++++++++
++++++++++
++++++++++
++++++++++
++++++++++
++++++++++
++++++
Private Sub btnLog_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLog.Click
Dim objConnection As New OleDbConnection(strConnect
ion)
Dim objCommand As New OleDbCommand
Dim iRowsAffected As Integer
objCommand.Connection = objConnection
objCommand.CommandText = "INSERT INTO StudentAttendance ( TimeLog ,StudentID, DateRecord ) VALUES (" & Now.ToLongTimeString & "," & txtID.Text & "," & Now.ToLongDateString & ")"
objCommand.CommandType = CommandType.Text
Try
objConnection.Open()
iRowsAffected = objCommand.ExecuteNonQuery
()
MessageBox.Show("Rows affected: " & iRowsAffected, "Rows")
MessageBox.Show("You Logged: " & txtID.Text & " On " & Format(Now, "mm-dd-yy").ToString & " " & Format(Now, "hh:mm:ss tt").ToString)
Catch oledbexception As OleDbException
MessageBox.Show(oledbexcep
tion.Messa
ge, "Access Queries")
End Try
objCommand.Dispose()
objCommand = Nothing
objConnection.Close()
objConnection.Dispose()
objConnection = Nothing
End Sub
++++++++++++++++++++++++++
+++++
this is a button event,when this event is triggered the time and date should append to the database but sadly it wont instead it shows me an exception message like this written below:
Syntax error (missing operator) in query expression '8:44:44 AM'.
though the time varies depending on the current time of my system -> '8:44:44 AM'.
Start Free Trial