2

我很难使用这个 SQL 插入命令。我已经编写了其他可以正常工作的插入命令,但是这个命令一直给我一个错误,上面写着“INSERT INTO 语句中的语法错误”。有人可以帮我看看我错过了什么吗?

        bool recordSaved;

        // Opens a connection to the database

        OleDbParameter param = new OleDbParameter();
        OleDbConnection conn = new OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" + Path + "");
        conn.Open();
        OleDbCommand command = conn.CreateCommand();

        string strSQL;

        command.Parameters.Add(new OleDbParameter("@Password", Password));
        command.Parameters.Add(new OleDbParameter("@FName", FName));
        command.Parameters.Add(new OleDbParameter("@LName", LName));
        command.Parameters.Add(new OleDbParameter("@Street", StreetAddress));
        command.Parameters.Add(new OleDbParameter("@City", City));
        command.Parameters.Add(new OleDbParameter("@State", State));
        command.Parameters.Add(new OleDbParameter("@Zip", Zip));
        command.Parameters.Add(new OleDbParameter("@Phone", PhoneNumber));
        command.Parameters.Add(new OleDbParameter("@CCType", CCType));
        command.Parameters.Add(new OleDbParameter("@CCNum", CCNumber));

        // Inserts a new user record into the database
        strSQL = "INSERT INTO tblUser (Password, FName, LName, StreetAddress, City, State, Zip, PhoneNumber, CCType, CCNumber) " +
            "VALUES (@Password, @FName, @LName, @Street, @City, @State, @Zip, @Phone, @CCType, @CCNum)";            

        // Stores the strSQL insert statement into a command object
        command.CommandText = strSQL;

        // Executes the insert statement
        command.ExecuteNonQuery();
        command.Parameters.Clear();

        // Closes the connection to the database
        conn.Close();
4

1 回答 1

5

看起来密码可能是您的问题。尝试在它周围加上括号 INSERT INTO tblUser ([Password]。从我刚刚读到的它是 jet.oledb 的保留字。

于 2013-10-16T21:50:02.150 回答