sql关键字附近的语法不正确

dpiehjr4  于 2021-07-24  发布在  Java
关注(0)|答案(1)|浏览(417)

如何修复这些错误?

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 System.Data.SqlClient;

namespace Adatbázis_kezelés
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\Szabolcs\Documents\Test.mdf;Integrated Security=True;Connect Timeout=30");
        private void button1_Click(object sender, EventArgs e)
        {
            con.Open();
            String query = "insert into Table (id,Name,Fname,Age,Gender,Addres) VALUES('"+textBox1.Text+ "','" + textBox2.Text + "','" + textBox3.Text + "','" + textBox4.Text + "','" + comboBox1.Text + "','" + textBox5.Text + "')";
            SqlDataAdapter SDA = new SqlDataAdapter(query, con);
            SDA.SelectCommand.ExecuteNonQuery();
            con.Close();
            MessageBox.Show("INSTERTION SUCCESSFULLY !!!");
        }
    }
}
xpszyzbs

xpszyzbs1#

作为 Table 是sql中的保留字,您应该将其括在括号中。

INSERT INTO [Table] ...

相关问题