运行此代码时出现错误。错误存在于我使用“插入”语句的地方。我无法理解是什么问题。
错误:INSERT INTO 语句中的语法错误
请告诉我给定代码中的问题在哪里
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.OleDb;
namespace GTC
{
public partial class Adminhome : Form
{
public Adminhome()
{
InitializeComponent();
}
OleDbConnection cn = new OleDbConnection("provider=microsoft.ace.oledb.12.0;data source=|DataDirectory|/GTC.accdb;");
void clear()
{
textBox1.Text = "";
comboBox1.Text = "-Select-";
textBox2.Text = "";
textBox3.Text = "";
textBox4.Text = "";
textBox5.Text = "";
}
private void Form1_Load(object sender, EventArgs e)
{
cn.Open();
// TODO: This line of code loads data into the 'GTCDataSet2.Society' table. You can move, or remove it, as needed.
this.SocietyTableAdapter.Fill(this.GTCDataSet2.Society);
// TODO: This line of code loads data into the 'GTCDataSet2.User' table. You can move, or remove it, as needed.
this.UserTableAdapter.Fill(this.GTCDataSet2.User);
this.reportViewer1.RefreshReport();
this.reportViewer2.RefreshReport();
}
private void button2_Click(object sender, EventArgs e)
{
try
{
String q = String.Format("insert into Society values('{0}')", textBox5.Text);
OleDbCommand cmd = new OleDbCommand(q, cn);
cmd.ExecuteNonQuery();
label8.Text = "Society Added...";
clear();
}
catch (Exception err)
{
label8.Text = err.Message;
}
}
private void button1_Click_1(object sender, EventArgs e)
{
try
{
String q = String.Format("insert into User values('{0}','{1}','{2}','{3}','{4}')", textBox1.Text, comboBox1.Text, textBox2.Text, textBox3.Text, textBox4.Text);
OleDbCommand cmd = new OleDbCommand(q, cn);
cmd.ExecuteNonQuery();
label6.Text = "User Added...";
clear();
}
catch (Exception err)
{
label6.Text = err.Message;
}
}
}
}