INSERT INTO语句中的C#语法错误。我没有看到什么?

时间:2013-10-16 21:44:07

标签: c# sql oledb insert-into

我在使用这个SQL Insert命令时遇到了困难。我已经写了其他插入命令,但是这个命令一直给我一个错误,上面写着“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();

1 个答案:

答案 0 :(得分:5)

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