Brian,
When you are using the OleDBCommand to execute a paramaterized query, the
parameters must be added to the command in the same order they appear in the
SQL statement. Move the DateAsked Parameter.add statement to after the
questionText Parameter.Add statement.
Also, try using Date.Today.ToSt ring instead of Now.Date. Just an issue of
using the .Net Framework version instead of the VB compatibility version.
This should fix the problem.
*************** *************
Dim cmdPostQuestion As New OleDb.OleDbComm and("INSERT INTO hd_questionsask ed
(askedBy,questi onText,dateAske d) VALUES (?,?,?)")
cmdPostQuestion .Connection = dbConnection
If dbConnection.St ate = ConnectionState .Closed Then
dbConnection.Op en()
End If
cmdPostQuestion .Parameters.Add ("askedBy", OleDb.OleDbType .VarWChar).Valu e =
getUserName()
cmdPostQuestion .Parameters.Add ("questionText" ,
OleDb.OleDbType .VarWChar).Valu e =Me.txtAskedQue stion.Text
cmdPostQuestion .Parameters.Add ("dateAsked" , OleDb.OleDbType .DBDate).Value =
Date.Today.ToSt ring
cmdPostQuestion .ExecuteNonQuer y()
dbConnection.Cl ose()
*************** *************** ********
Kirk Graves
"Brian Henry" <br******@adelp hia.net> wrote in message
news:%2******** *******@tk2msft ngp13.phx.gbl.. .
I have an access database, and one of the fields in the table I am
inserting into has a date/time data type. What is the correct OleDb data type to
insert the date and time that it is at the moment that the record was
inserted at. I had this, but it gives me a "data type mismatch" error on
run.
Dim cmdPostQuestion As New OleDb.OleDbComm and("INSERT INTO
hd_questionsask ed (askedBy,questi onText,dateAske d) VALUES (?,?,?)")
cmdPostQuestion .Connection = dbConnection
If dbConnection.St ate = ConnectionState .Closed Then
dbConnection.Op en()
End If
cmdPostQuestion .Parameters.Add ("askedBy", OleDb.OleDbType .VarWChar).Valu e
= getUserName()
cmdPostQuestion .Parameters.Add ("dateAsked" , OleDb.OleDbType .DBDate).Value
= Now.Date
cmdPostQuestion .Parameters.Add ("questionText" ,
OleDb.OleDbType .VarWChar).Valu e = Me.txtAskedQues tion.Text
cmdPostQuestion .ExecuteNonQuer y()
dbConnection.Cl ose()
if i take out anything relateing to the date, it works just fine...