Answer the question
In order to leave comments, you need to log in
How to fix the error - "data truncate for column"?
these are tables in the database
and pictures with errors why it cannot recognize a field with a float format and a field with a datetime format
here is the code with a datetime error
private void button1_Click(object sender, EventArgs e)
{
MySqlConnectionStringBuilder mysqlCSB;
mysqlCSB = new MySqlConnectionStringBuilder();
mysqlCSB.Server = "127.0.0.1";
mysqlCSB.Database = "vlados";
mysqlCSB.UserID = "root";
mysqlCSB.Password = "T2(!)3672+family";
using (MySqlConnection cn = new MySqlConnection(mysqlCSB.ConnectionString))
{
try
{
cn.Open();
string SInsSql = "Insert into servicesandbooking(idbooking, Databooking, id_orders, idstaff, idguests) Values(' { 0 } ',' { 1 } ',' { 2 } ',' { 3 } ',' { 4 } ')";
int idbooking = Convert.ToInt32(textBox1.Text);
DateTime Databooking = dateTimePicker1.Value;
int id_orders = Convert.ToInt32(textBox2.Text);
int idstaff = Convert.ToInt32(textBox3.Text);
int idguests = Convert.ToInt32(textBox4.Text);
string sInsSotr = string.Format(SInsSql, idbooking, Databooking, id_orders, idstaff, idguests);
MySqlCommand cmdIns = new MySqlCommand(sInsSotr, cn);
cmdIns.ExecuteNonQuery();
MessageBox.Show("Запись успешно вставлена !");
cn.Close();
}
catch (MySqlException ex)
{
MessageBox.Show(ex.Message);
}
}
}
и код с ошибкой поля типа float
private void button1_Click(object sender, EventArgs e)
{
MySqlConnectionStringBuilder mysqlCSB;
mysqlCSB = new MySqlConnectionStringBuilder();
mysqlCSB.Server = "127.0.0.1";
mysqlCSB.Database = "vlados";
mysqlCSB.UserID = "root";
mysqlCSB.Password = "T2(!)3672+family";
using (MySqlConnection cn = new MySqlConnection(mysqlCSB.ConnectionString))
{
try
{
cn.Open();
string SInsSql = "Insert into menu(id_orders, Nname, serving_size, cost, cooking_time) Values('{0}','{1}','{2}','{3}','{4}')";
int id_orders = Convert.ToInt32(textBox4.Text);
string Nname = textBox1.Text;
int serving_size = Convert.ToInt32(textBox2.Text);
int cost = Convert.ToInt32(textBox3.Text);
float cooking_time = float.Parse(textBox5.Text);
string sInsSotr = string.Format(SInsSql, id_orders, Nname, serving_size, cost, cooking_time);
MySqlCommand cmdIns = new MySqlCommand(sInsSotr, cn);
cmdIns.ExecuteNonQuery();
MessageBox.Show("Запись успешно вставлена !");
cn.Close();
}
catch (MySqlException ex)
{
MessageBox.Show(ex.Message);
}
}
}
Answer the question
In order to leave comments, you need to log in
It's not a mistake. It's just a message that the data has been truncated to fit. Just catch this exception separately from all other MySqlException (it probably has a different class there)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question