473,402 Members | 2,072 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,402 software developers and data experts.

C# MS Access DateTime insert query error Please

hello guys,

I have little experience working with C# and MS Access ...

I am having an insert query with one datetime field and a boolean and couple
of text and number fields as below:

"Insert into order (OrderClientID, OrderDate, OrderOfferID, OrderIsSpecial,
OrderShipment) Values (6, # 16/09/2005 2:38:51 PM # , 1 , 0 , 'hello there
it is test')"

The second parametter is Date format, and the 4th one is boolean. I tryed
false and 0 but both didn't work.

I create my string as below:

string strTable="Insert into order";

string strFields=" (OrderClientID, OrderDate, OrderOfferID, OrderIsSpecial,
OrderShipment)";

string strValues= " Values (" + personID +

", # " + System.DateTime.Now.ToString() +

" #, " + 1 +

", " + 0 +

" ,'" + shipment + "')";

string insertStr = strTable + strFields + strValues;

it raises SQL insert error while try to add.

what is going wrong here?
Nov 19 '05 #1
5 15386

What sql error is getting raised ?

You can try running the same query in Access.
1) Open the access db
2) Goto queries tab
3) Click "New Query"
4) Paste your insert statement in "SQL" view

Execute the query & see what error does it raise
It will be easy to find the source of error there. If you find what is
the problem, change the query

Does this help ?

Kalpesh

Nov 19 '05 #2
Try using parameterized queries whenever possible. They're easier and safer.
Example:

string qry = "INSERT INTO MyTable (MyDateCol) VALUES(?)";

OdbcParameter parm = new System.Data.Odbc.OdbcParameter("@DateTimeValue",
System.Data.SqlDbType.DateTime);
parm.Value = DateTime.Now;

//Now create a command and set "qry" as the command text and add "parm" to
//the parameters collection.
I'm positive I've done this before, but it's been a while, so my syntax may
not be 100% correct. (I'm pretty sure "?" is used to represent the param in
the query string...) In any case, this methodology is the "best" way to do it
when you can't use a stored procedure.

"Annie" wrote:
hello guys,

I have little experience working with C# and MS Access ...

I am having an insert query with one datetime field and a boolean and couple
of text and number fields as below:

"Insert into order (OrderClientID, OrderDate, OrderOfferID, OrderIsSpecial,
OrderShipment) Values (6, # 16/09/2005 2:38:51 PM # , 1 , 0 , 'hello there
it is test')"

The second parametter is Date format, and the 4th one is boolean. I tryed
false and 0 but both didn't work.

I create my string as below:

string strTable="Insert into order";

string strFields=" (OrderClientID, OrderDate, OrderOfferID, OrderIsSpecial,
OrderShipment)";

string strValues= " Values (" + personID +

", # " + System.DateTime.Now.ToString() +

" #, " + 1 +

", " + 0 +

" ,'" + shipment + "')";

string insertStr = strTable + strFields + strValues;

it raises SQL insert error while try to add.

what is going wrong here?

Nov 19 '05 #3
Well, my question was what was wrong with my query? I already tested the
query by running it in MS Access
but still error ... I don't know what is wrong? what format MS Access
accepts as input for date and boolean
fields from C#. that was basically my question ...

thanks anyways ,,,
"Annie" <my**************@gmail.com> wrote in message
news:43******@dnews.tpgi.com.au...
hello guys,

I have little experience working with C# and MS Access ...

I am having an insert query with one datetime field and a boolean and
couple of text and number fields as below:

"Insert into order (OrderClientID, OrderDate, OrderOfferID,
OrderIsSpecial, OrderShipment) Values (6, # 16/09/2005 2:38:51 PM # , 1 ,
0 , 'hello there it is test')"

The second parametter is Date format, and the 4th one is boolean. I tryed
false and 0 but both didn't work.

I create my string as below:

string strTable="Insert into order";

string strFields=" (OrderClientID, OrderDate, OrderOfferID,
OrderIsSpecial, OrderShipment)";

string strValues= " Values (" + personID +

", # " + System.DateTime.Now.ToString() +

" #, " + 1 +

", " + 0 +

" ,'" + shipment + "')";

string insertStr = strTable + strFields + strValues;

it raises SQL insert error while try to add.

what is going wrong here?

Nov 19 '05 #4
What is the position of the cursor when the error is raised while
running query in MS-Access query editor ?

Also, there need not be space before & after the date value

Does it help?

Kalpesh

Nov 19 '05 #5
Here we go finally I found it!!!!
ORDER is a bloody reserved word in MS Access and therefore can't be used as
TABLE NAME!
So I changed the name to ORDERS and now it works!
What a pain, we they didn't set they error in a more informed way "Order is
a reserved word and cann't be used" ...
what a crap!
Hope it helps anyone else!

"Annie" <my**************@gmail.com> wrote in message
news:43******@dnews.tpgi.com.au...
hello guys,

I have little experience working with C# and MS Access ...

I am having an insert query with one datetime field and a boolean and
couple of text and number fields as below:

"Insert into order (OrderClientID, OrderDate, OrderOfferID,
OrderIsSpecial, OrderShipment) Values (6, # 16/09/2005 2:38:51 PM # , 1 ,
0 , 'hello there it is test')"

The second parametter is Date format, and the 4th one is boolean. I tryed
false and 0 but both didn't work.

I create my string as below:

string strTable="Insert into order";

string strFields=" (OrderClientID, OrderDate, OrderOfferID,
OrderIsSpecial, OrderShipment)";

string strValues= " Values (" + personID +

", # " + System.DateTime.Now.ToString() +

" #, " + 1 +

", " + 0 +

" ,'" + shipment + "')";

string insertStr = strTable + strFields + strValues;

it raises SQL insert error while try to add.

what is going wrong here?

Nov 19 '05 #6

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

Similar topics

4
by: Malcolm Diaz | last post by:
Hello all Thank you all in advance. I am completely at a loss here with this error. I am developing a simple interface that will allow a user to enter,execute and view results from a SQL statement...
1
by: Dan Caron | last post by:
I have this stored procedure below that works great in SQL Server. The sql purges rows out of a table, leaving "x" # of rows in the table ("x" = s.RetainHistoryNum below). Now I need it to run in...
8
by: craigkenisston | last post by:
I have a generic function that receives a couple of datetime values to work with. They can or cannot have a value, therefore I wanted to use null. This function will call a database stored...
2
by: Shapper | last post by:
Hello, I am trying to insert a record in an Access database using Asp.Net/Vb.Net. I am getting the error: "Operation must use an updateable query." How can I solve this problem? The code...
1
by: suslikovich | last post by:
Hi all, I am getting this error when insert values from one table to another in the first table the values are varchar (10). In the second they are datetime. The format of the data is mm/dd/yyyy...
4
by: Arpan | last post by:
A SQL Server 2005 DB table has 4 columns namely "ID" (IDENTITY int column), "FirstName" (varchar(50)), "LastName" (varchar(50)) & "DOB" (datetime). Now when I am trying to add a new row using the...
2
by: tmarunkumarit | last post by:
I want to insert datetime values into msaccess using asp.net by vb.. Am getting error that Syntax Error in INSERT INTO statement... My query is strSQL="insert into group0...
4
by: etuncer | last post by:
Hello All, I have Access 2003, and am trying to build a database for my small company. I want to be able to create a word document based on the data entered through a form. the real question is...
4
by: SilentThunderer | last post by:
Hey folks, Let me start out by letting you know what I'm working with. I'm building an application in VB 2005 that is basically a userform that employees can use to "Clock in". The form...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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,...
0
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...

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.