data type problem with ado to access db... date/time field

  • Thread starter Thread starter Brian Henry
  • Start date Start date
B

Brian Henry

i get this error "datatype mismatch" when i do the code below, it works if i
take out the date field.. this is to an access database with a date/time
column... please tlel me what im doing wrong.. thanks!

' If Not IsPostBack Then

Dim cmdPostQuestion As New OleDb.OleDbCommand("INSERT INTO hd_questionsasked
(askedBy,questionText,dateAsked) VALUES (?,?,?)")

cmdPostQuestion.Connection = dbConnection

If dbConnection.State = ConnectionState.Closed Then

dbConnection.Open()

End If

cmdPostQuestion.Parameters.Add("askedBy", OleDb.OleDbType.VarWChar).Value =
getUserName()

cmdPostQuestion.Parameters.Add("dateAsked", OleDb.OleDbType.DBDate).Value =
Now.Date

cmdPostQuestion.Parameters.Add("questionText",
OleDb.OleDbType.VarWChar).Value = Me.txtAskedQuestion.Text

cmdPostQuestion.ExecuteNonQuery()



dbConnection.Close()

' End If

Response.Redirect("/hd_questionasked.aspx")





by the way i tried oledb.oledbtype.date also and it gave me the mismatch
error still..
 
i get this error "datatype mismatch" when i do the code below, it works if i
take out the date field.. this is to an access database with a date/time
column... please tlel me what im doing wrong.. thanks!

' If Not IsPostBack Then

Dim cmdPostQuestion As New OleDb.OleDbCommand("INSERT INTO hd_questionsasked
(askedBy,questionText,dateAsked) VALUES (?,?,?)")

cmdPostQuestion.Connection = dbConnection

If dbConnection.State = ConnectionState.Closed Then

dbConnection.Open()

End If

cmdPostQuestion.Parameters.Add("askedBy", OleDb.OleDbType.VarWChar).Value =
getUserName()

cmdPostQuestion.Parameters.Add("dateAsked", OleDb.OleDbType.DBDate).Value =
Now.Date

cmdPostQuestion.Parameters.Add("questionText",
OleDb.OleDbType.VarWChar).Value = Me.txtAskedQuestion.Text

cmdPostQuestion.ExecuteNonQuery()



dbConnection.Close()

' End If

Response.Redirect("/hd_questionasked.aspx")





by the way i tried oledb.oledbtype.date also and it gave me the mismatch
error still..
Maybe oleDB doesn't support named parameters? Try moving the date
parameter to the last position so it matches the insert statement.
 
Brian,
Do your functions return Unicode or just strings? You may need to use
OleDbType.VarChar instead of VarWChar. This may also be true if the
database is not expecting Unicode.

Ron Allen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top