473,804 Members | 3,203 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.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...
Nov 17 '05 #1
1 2320
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...

Nov 17 '05 #2

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

Similar topics

0
3733
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 text boxes how do I stop this and how would I code it to redirect to a thank you page. All with out the help of a web server this has to br ran from the desktop and with in IE with a local directory. Pleas help I am stuck. here is the code! ...
4
11838
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 completed. here's the code: System.Data.OleDb.OleDbConnection hist_cnn = new System.Data.OleDb.OleDbConnection(); System.Data.OleDb.OleDbCommand hist_command = new System.Data.OleDb.OleDbCommand();
2
2317
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 them.. is there a sheet somewhere or a refrence for them? all i really need to know is Access ADO.NET Numeric Integer/numeric? Memo VarWChar? Text VarWChar? Date/Time ?...
1
521
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 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 (?,?,?)") ...
3
8843
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 don't think I made any changes to either page other than changing the user control that creates the header). Server Error in '/myApp' Application. ---------------------------------------------------------------------------- ----
0
5680
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 System.Data.Common.DbDataAdapter.Update(DataSet dataSet, String srcTable) at System.Data.Common.DbDataAdapter.Update(DataSet dataSet) at TryThis.Form1.save() in C:\Documents and Settings\Nick\My Documents\...
5
2230
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 then..... what should I do?
3
2912
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 assembly I am developing. I am going to use the data Access Application Block for data access in my DLL assembly, and a Windows Service will execute the DLL on a set schedule. To make this happen I will add the Common, Configuration, and Data...
11
1624
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 sqlDataReader, dim y as OLEDBDatareader in lots of parts of the app) Could I not just avoid this and use OLEDB for both database types? Whats the best way - OLEDB or to create some kind of data access layer
0
9708
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9587
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10588
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10340
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10324
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9161
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7623
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5662
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4302
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.