PC Review


Reply
Thread Tools Rate Thread

Data type question for OLEdb data types

 
 
Brian Henry
Guest
Posts: n/a
 
      4th Oct 2003
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.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()


if i take out anything relateing to the date, it works just fine...


 
Reply With Quote
 
 
 
 
Kirk
Guest
Posts: n/a
 
      5th Oct 2003
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.ToString 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.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("questionText",
OleDb.OleDbType.VarWChar).Value =Me.txtAskedQuestion.Text

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

cmdPostQuestion.ExecuteNonQuery()
dbConnection.Close()
**************************************

Kirk Graves

"Brian Henry" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> 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.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()
>
>
> if i take out anything relateing to the date, it works just fine...
>
>



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
A first chance exception of type 'System.Data.OleDb.OleDbException' occurred in System.Data.dll sirinath Microsoft ADO .NET 2 8th Oct 2007 05:49 PM
System.Data.OleDb.OleDbException: Data type mismatch in criteria expression. psychomad Microsoft ASP .NET 2 10th Apr 2007 08:31 PM
Data Types when using Jet.OLEDB.4.0 with Excel datasource Martin Newman Microsoft Access External Data 4 14th Aug 2004 07:11 PM
Data type question for OLEdb data types Brian Henry Microsoft ADO .NET 1 5th Oct 2003 04:18 PM
Data type question for OLEdb data types Brian Henry Microsoft ASP .NET 1 5th Oct 2003 04:18 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:30 AM.