4
Answers

Date time cant insert in database

prince raj

prince raj

10y
1k
1
 hello, i cant insert in database.

if i remove date in insert query its work completely.
 
string query = "insert into income_new(Cid, rs, rate, period, date) values ('" + cid + "','" + txt_Rs.Text.Trim() + "','" + txt_Rate.Text.Trim() + "','" + txt_Period.Text.Trim() + "','" + DateTime.Now + "')";
 
and datatype of date in access database is Date/Time. so...
 
----------
thanks in advance. 
Answers (4)
0
Vasu Gadhiya

Vasu Gadhiya

NA 594 59.1k 10y
however you take Column name "Date".

date is a reserved keyword.
You need to use square brackets around it to use in a query.

-------------------------------
string query = "insert into income_new(Cid, rs, rate, period, [date]) values ('" + cid + "','" + txt_Rs.Text.Trim() + "','" + txt_Rate.Text.Trim() + "','" + txt_Period.Text.Trim() + "','" + DateTime.Now + "')";
-------------------------------

If it is possible, I strongly suggest to change these names because you will have this problem everytime you hit this table.

Access 2007 reserved words and symbols
http://office.microsoft.com/en-us/access-help/access-2007-reserved-words-and-symbols-HA010030643.aspx
Accepted
0
prince raj

prince raj

NA 88 26.6k 10y
Thanks Vasu Gadhiya

its my fault to use keyword as Column name.
0
Anupam Singh

Anupam Singh

NA 5.8k 886.7k 10y
Hi prince ,

You can try to insert DateTime.Today instead of DateTime.Now
0
Akhil Mittal

Akhil Mittal

NA 21.9k 2.9m 10y
I think you need to check with the format of datetime that your are inserting