1

当我与 access 数据库连接时遇到问题,然后我在 INSERT INTO 语句中收到错误语法错误。我的代码是:

 string str = ("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:/Users/Geeta/Desktop/Database2.accdb;Persist Security Info=False;");
        OleDbConnection conn = new OleDbConnection(str);
        conn.Open();
        string query = "insert into data (FirstName,Email,Password,Address) values ('" + 
            txt_fstname.Text + "','" + txt_email.Text + "', '" + 
            txt_pass.Text + "', '" + txt_add.Text + "')";
        OleDbCommand cmd = new OleDbCommand(query,conn);
        cmd.ExecuteNonQuery();
        conn.Close();
        Response.Redirect("Default.aspx");

请建议我。

“谢谢”

4

1 回答 1

3

密码是 Jet/ACE SQL 中的保留字,因此您必须将其括在方括号中:

string query = "insert into data (FirstName,Email,[Password],Address) values ('" + 
于 2012-04-13T08:32:12.240 回答