473,405 Members | 2,141 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Data type question for OLEdb data types

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...
Nov 17 '05 #1
1 2293
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" <br******@adelphia.net> wrote in message
news:%2***************@tk2msftngp13.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.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...

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: TheCoder | last post by:
I am making a D-base with web conectivity for my class project. I have everything working but the subit button sends the data to the correct fields but afterwards it wants to reproduce new blank...
4
by: authorking | last post by:
I use the following code to insert a data record in to a datatable of an access database.But every time I execute the command, there will rise an exception and the insert operation can't be...
2
by: Brian Henry | last post by:
is there info about data type conversions between access to ado.net? I have tried a lot of the ones that say oledb data types should work for and get a lot of "data type mismatch" errors using...
1
by: Brian Henry | last post by:
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...
3
by: Brian Foree | last post by:
I am developing an ASP.NET application that uses Access 2000 as its backend, and have just started getting the following error on 2 ASP.NET pages that had been working until late last week (and I...
0
by: NicK chlam via DotNetMonster.com | last post by:
this is the error i get System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement. at System.Data.Common.DbDataAdapter.Update(DataRow dataRows, DataTableMapping tableMapping) at...
5
by: Gene | last post by:
What can I do if I want to get the result using the sql command? for example, the select command is "select Name from Employee where StaffID=10" How to get the "Name"??? dim Name as string and...
3
by: SAL | last post by:
Hi, I have Microsoft Enterprise Library 2005 installed on my local system. I'm developing in C# using Visual Studio 2003 IDE with framework 1.1. I am automating a process that will use a DLL...
11
by: sanders_mike_newsgroups | last post by:
Hi I have a web app that needs to be able to use either SQL Server or MS Access - depending upon the installation. I want to avoid having unnessesary amounts of code (eg: dim x as...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.