Не вносятся данные в БД. C#, WinForm выдает ошибку в if (command.ExecuteNonQuery() == 1)
Ошибка: MySql.Data.MySqlClient.MySqlException: "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1" Вроде все делал правильно, но не может отправить данные.
using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
namespace Проект
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{
Close();
}
private void button1_Click(object sender, EventArgs e)
{
Double a;
Double b;
Double c;
Double d;
Double s;
Double t;
a = Convert.ToDouble(text1sem.Text);
b = Convert.ToDouble(text1kon.Text);
c = Convert.ToDouble(text2sem.Text);
d = Convert.ToDouble(text2kon.Text);
s = Convert.ToDouble(textitog.Text);
t = (a + b + c + d + s) / 5 * 20;
Itog.Text = Convert.ToString(t);
DB db = new DB();
MySqlCommand command = new MySqlCommand("INSERT INTO `рейтинг успеваемости` (`Фамилия`, `Имя`, `Отчество`, `1 семестр`, `1 контрольная точка`, `2 семестр`, `2 контрольная точка`, `Итоговая аттестационная`, `Общий рейтинг`) VALUES (@Famaly, @Name, @otce, @1sem, @1kon, @2sem, @2kon, @ates, @reit", db.getConnection());
command.Parameters.Add("@Famaly", MySqlDbType.VarChar).Value = textfameli.Text;
command.Parameters.Add("@Name", MySqlDbType.VarChar).Value = textname.Text;
command.Parameters.Add("@otce", MySqlDbType.VarChar).Value = textotces.Text;
command.Parameters.Add("@1sem", MySqlDbType.Float).Value = text1sem.Text;
command.Parameters.Add("@1kon", MySqlDbType.Float).Value = text1kon.Text;
command.Parameters.Add("@2sem", MySqlDbType.Float).Value = text2sem.Text;
command.Parameters.Add("@2kon", MySqlDbType.Float).Value = text2kon.Text;
command.Parameters.Add("@ates", MySqlDbType.Float).Value = textitog.Text;
command.Parameters.Add("@reit", MySqlDbType.Float).Value = Itog.Text;
db.openConnection();
if (command.ExecuteNonQuery() == 1)
MessageBox.Show("Данные сохранены");
else
MessageBox.Show("Данные не сохранены");
db.closeConnection();
}
}
}
Источник: Stack Overflow на русском