Insert date into a database

Insert date into a database

Postby rapo » Mon 18 Oct 2010 22:41

I'm using dotconnect with C# in VS2010 and I want to insert into a mysql database,5 strings that are from some textboxes and the date that is from a DateTimePicker. But I receive an error.
This is my code:
Code: Select all
public void SetMyCustomFormat()
            dtpAdaugare.CustomFormat = "yyyy-MM-dd";

        private void btAdd_Click(object sender, EventArgs e)
            comandaSQLObs.CommandText = "insert into observations(camera,name,mac,others,observations,Date) values(?,?,?,?,?,?)";
            comandaSQLObs.Parameters.Add("param1", tbCam.Text+tbLit.Text.ToUpper());
            comandaSQLObs.Parameters.Add("param2", cbPersoane.Text);
            comandaSQLObs.Parameters.Add("param3", tbmac.Text);
            comandaSQLObs.Parameters.Add("param4", tbAltele.Text);
            comandaSQLObs.Parameters.Add("param5", rtObs.Text);
            comandaSQLObs.Parameters.Add("param6", dtpAdaugare);
            comandaSQLObs.Connection = conexSQLObs;

I receive this error:
Incorrect date value: '' for column 'Dates' at row 1
Dates is the field from the database.
Posts: 2
Joined: Mon 04 Oct 2010 21:17

Postby Zero-G. » Wed 20 Oct 2010 10:47


Is it possible, that you have forgotten something?

Your postetd the code
Code: Select all

But I think, this should be something like:
Code: Select all

Hope this helps.
Posts: 390
Joined: Sat 09 Dec 2006 12:20

Postby Shalex » Wed 20 Oct 2010 13:26

Zero-G, thank you for your comments.

Rapo, if Zero-G's advice doesn't help, make sure that dtpAdaugare contains a value that is valid for MySQL's DATE.

Try to find out the reason of the problem with dbMonitor: ... nitor.html

Otherwise, send us a test project with the DDL/DML script to reproduce the issue in our environment. Also specify the versions of your dotConnect for MySQL (the Tools > MySQL > About menu of Visual Studio) and MySQL Server.
Devart Team
Posts: 7284
Joined: Thu 14 Aug 2008 12:44

Return to dotConnect for MySQL