473,666 Members | 2,101 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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="Inser t 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 15408

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.Odb c.OdbcParameter ("@DateTimeValu e",
System.Data.Sql DbType.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="Inser t 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******@d news.tpgi.com.a u...
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="Inser t 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******@d news.tpgi.com.a u...
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="Inser t 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
4378
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 to our oracle database. I have found that I can not query more than a single day at a time when using a date > 12/31/2002 as my where clause For example select * from tclaim where (process_date >= to_date('02/01/04', 'mm/dd/yy')) and (process_date...
1
1802
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 MS Access. The thing that throws me off is the multiple "from" statements. I have tried a dozen different queries, nothing seems to do the trick. Either I end up with an syntax error, or I end up with inaccurate results. Dan
8
4329
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 procedure and must save either a null or a real date. However, passing a hardcoded "null" to call this function causes a compilation error : cx.cs(136): Argument '16': cannot convert from '<null>' to 'System.DateTime'
2
1305
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 I am using is:
1
5467
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 to be easily converted to dates. The conversion in this case is implicit as indicated in SQL Server documentation. Here is my query: INSERT INTO Campaign (CampaignID, Name, DateStart, DateEnd, ParentID, ListID) SELECT ...
4
8667
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 following INSERT statement: sqlDapter.InsertCommand = New SqlCommand sqlDapter.InsertCommand.CommandText = "INSERT INTO UserDetailss VALUES('bobby','simpson','" & Now() & "')" sqlDapter.InsertCommand.Connection = sqlConn sqlDapter.Update(dSet,...
2
3432
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 (name,addressline1,addressline2,landmark,city,state,pincode,telephone1,telephone2,altcontactno,businesscategory,product,category,date) values('" & txtname.text & "','" & txtadds1.text & "','" & txtadds2.text & "','" & txtland.text & "', '" & txtcity.text & "', '" &...
4
12428
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 this: can Access create the document and place it as an OLE object to the relevant table? Any help is greatly appreciated. Ricky
4
6802
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 allows the employee to enter their UserID and select "Login" or "Logout" and then click a submit. When the submit button is clicked, I want the application to dum the NT Userename, UserID, status (Login or Logout) and a date/time stamp into an MS Access...
0
8449
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
8784
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
8556
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
7387
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
6198
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
4371
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2774
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
2
2011
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1777
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.