问题访问插入语法

时间:2010-08-05 18:19:27

标签: ms-access oledb

我不明白! 我正在访问数据库中进行简单的插入。

static void EcrireDansBD()
{
    //Connection a la BD
    string connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;data source=me.mdb";

    OleDbConnection conn = new OleDbConnection(connectionString);

    //works
    string sql = "INSERT INTO HQ_POINTS (NORD,EST,ELEV) VALUES (1,2,3)";

    //Syntax error in INSERT INTO statement
    string sql = "INSERT INTO HQ_POINTS (NORD,EST,ELEV,DESC) VALUES (1,2,3,'ok')";

    //Syntax error in INSERT INTO statement
    string sql = "INSERT INTO HQ_POINTS (NORD,EST,ELEV,DESC) VALUES (1,2,3,ok)";

    //Syntax error in INSERT INTO statement
    string sql = "INSERT INTO HQ_POINTS (NORD,EST,ELEV,DESC) VALUES (1,2,3,\"ok\")";

    OleDbCommand cmd = new OleDbCommand(sql, conn);

    conn.Open(); 

    cmd.ExecuteNonQuery();

    conn.Close();

}

这是表格:

alt text http://img1.imagilive.com/0810/Capturee43.PNG

帮助?

1 个答案:

答案 0 :(得分:0)

DESC是一个保留关键字,用于排序(ORDER BY column ASC/DESC)。

你必须引用它:使用[DESC]代替