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

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

如何修复这些错误?

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.Data.SqlClient;
  11. namespace Adatbázis_kezelés
  12. {
  13. public partial class Form1 : Form
  14. {
  15. public Form1()
  16. {
  17. InitializeComponent();
  18. }
  19. SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\Szabolcs\Documents\Test.mdf;Integrated Security=True;Connect Timeout=30");
  20. private void button1_Click(object sender, EventArgs e)
  21. {
  22. con.Open();
  23. String query = "insert into Table (id,Name,Fname,Age,Gender,Addres) VALUES('"+textBox1.Text+ "','" + textBox2.Text + "','" + textBox3.Text + "','" + textBox4.Text + "','" + comboBox1.Text + "','" + textBox5.Text + "')";
  24. SqlDataAdapter SDA = new SqlDataAdapter(query, con);
  25. SDA.SelectCommand.ExecuteNonQuery();
  26. con.Close();
  27. MessageBox.Show("INSTERTION SUCCESSFULLY !!!");
  28. }
  29. }
  30. }
xpszyzbs

xpszyzbs1#

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

  1. INSERT INTO [Table] ...

相关问题