我尝试将方括号[]放入,将值作为参数传递并使用@,但它始终告诉我INSERT INTO语句出错。请帮助这是一个项目。 旁注:我已经添加了数据集并检查了它们的数据绑定,一切看起来都很好。
public partial class Form2 : Form
{
OleDbConnection Connect = new OleDbConnection();
public Form2()
{
InitializeComponent();
Connect.ConnectionString = @"Provider=Microsoft Office 12.0 Access Database Engine OLE DB Provider;Data Source=C:\Users\chich\Documents\Visual Studio 2017\Projects\my project\Proper_Database.accdb; Persist Security Info=False;";
}
private void button1_Click(object sender, EventArgs e)
{ try
{
Connect.Open();
OleDbCommand Cmd = new OleDbCommand();
Cmd.Connection = Connect;
Cmd.CommandText = "insert into User ([Username], [Password], [Firstname], [Lastname]) values('" + usernameTextBox1.Text+ "','" + passwordTextBox1.Text + "','" + firstnameTextBox.Text + "','" + lastnameTextBox.Text + "')";
Cmd.ExecuteNonQuery();
MessageBox.Show("It went");
Connect.Close();
}
catch (Exception ex)
{
MessageBox.Show("An Error occured " + ex);
}
Form3 forms = new Form3();
forms.Show();
}
谢谢