1

i am developing window application using visual studio and c# i want to insert date in Mysql database table which having datatype date

using datetimepicker control of visual studio

i wrote an insert query like this (insert into table name values('"+ datetimepicker.value + "')

it give me following error

ERROR [HY000] [MySQL][ODBC 3.51 Driver][mysqld-5.1.47-community]Incorrect datetime value: '01-06-2010 00:00:00' for column 'Date' at row 1

can any one resolve this problem

2
  • You need to use an ISO 8601 formatted date (YYYY-MM-DD HH:MM:SS), eg: "2010-06-02 12:34:56". I'm not supplying this as an answer because I don't know how to reformat the date in c# Commented Jun 1, 2010 at 16:09
  • thanks but how to use it in C# Commented Jun 1, 2010 at 16:12

2 Answers 2

2

Use parameterized queries instead. Your code is subject to SQL injection attacks.

Sign up to request clarification or add additional context in comments.

Comments

0

the Mysql DATE() datatype have the Format: YYYY-MM-DD.

you must trim out the time part of the .NET date type OR you can use the Mysql DateTime DataType.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.