public partial class Form1 : Form
{
static OleDbConnection con = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=chessclub.accdb");
static OleDbCommand cmd = con.CreateCommand();
static OleDbDataReader reader;
int count = 0;
public Form1()
{
InitializeComponent();
}
private void btncreate_Click(object sender, EventArgs e)
{
if (con.State.Equals(System.Data.ConnectionState.Open))
con.Close();
con.Open();
OleDbCommand cmd = con.CreateCommand();
cmd.CommandText = "INSERT INTO chess1db( names , schoolid , major , gender) + VALUES ( '" + txtname.Text + "','" + txtid.Text + "','" + txtmajor.Text + "','" + txtgndr.Text + "')";
cmd.Connection = con;
cmd.ExecuteNonQuery();
MessageBox.Show("Record submitted ");
con.Close();
}
}
每次我按下发送数据到数据库的按钮时,它都告诉我INSERT INTO
语句中有语法错误。这是什么问题?
1条答案
按热度按时间64jmpszr1#
这是个加号,拿掉它
但请务必使用 * 参数 *。