Anuya
Anuya

Reputation: 8350

Insert Date to MySql using c#

I have Date field in my mysql table. I want to insert the date through my Date picker control of windows forms c#. How ?

when i tried using below, i am getting error.

Code :

DB.Insert_Orders(Convert.ToInt32(txtA.Text), Convert.ToInt32(txtB.Text), Convert.ToInt32(txtC.Text), DTP_date.Value.ToString("yyyy/MM/dd"));


Error :
{MySql.Data.MySqlClient.MySqlException: Incorrect datetime value: '15' for column 'Date' at row 

Upvotes: 2

Views: 15177

Answers (2)

gsoni
gsoni

Reputation: 1146

You need to convert the value of datetime picker in to type DateTime. Then pass the value.

Upvotes: 0

Kru
Kru

Reputation: 149

Try

DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");

Or

DateTime.Now.ToString("yyyyMMddHHmmss");

Upvotes: 6

Related Questions