views:

18

answers:

1

I don't get it! I'm doing a simple insert in an access db.

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();

}

Here is the table:

alt text

Help?

A: 

DESC is a reserved keyword which is used for ordering (ORDER BY column ASC/DESC).

you have to quote it: use [DESC] instead

knittl
You are so right, I am so blind;
Enriquev