如何修复这些错误?
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 !!!");
}
}
}
1条答案
按热度按时间xpszyzbs1#
作为
Table
是sql中的保留字,您应该将其括在括号中。