Insert date into a database
Posted: 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:
I receive this error:
Incorrect date value: '' for column 'Dates' at row 1
Dates is the field from the database.
This is my code:
Code: Select all
public void SetMyCustomFormat()
{
dtpAdaugare.CustomFormat = "yyyy-MM-dd";
}
private void btAdd_Click(object sender, EventArgs e)
{
SetMyCustomFormat();
conexSQLObs.Open();
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;
comandaSQLObs.ExecuteNonQuery();
conexSQLObs.Close();
this.Close();
}
Incorrect date value: '' for column 'Dates' at row 1
Dates is the field from the database.