Syntax error in insert statement

Discussion in 'ASP .Net' started by eric dugal, Jul 31, 2004.

  1. eric dugal

    eric dugal Guest

    Hi all!!

    I need your help.... i'm working since 2 hours on a simple insert statement,
    but couldn't handle it.

    Here is my code :

    public int ExecQuery(string SqlString)

    {


    OleDbConnection oCoon = new OleDbConnection(connectionString);

    oCoon.Open();

    OleDbCommand cmd3 = new OleDbCommand();

    cmd3.Connection = oCoon;

    cmd3.CommandText = SqlString;

    if(oCoon.State == ConnectionState.Closed)

    {

    oCoon.Open();

    }

    cmd3.ExecuteNonQuery();

    return 1

    }



    When the code reach the cmd3.ExecuteNonQuery(); I always receive the
    followin error :

    SYNTAX ERROR IN INSERT INTO STATEMENT....

    But, i tried to put some debug info (Debug.Write) and my SQL statement seem
    ok.



    SQL Statement : INSERT INTO COLORS (agent_no,primary,secondary) VALUES
    (3,'fff','ALLO')



    Any idea??

    Thanks,
    eric dugal, Jul 31, 2004
    #1
    1. Advertising

  2. primary is a reserved word. Put this instead [primary]

    "eric dugal" <> wrote in message
    news:d8POc.113688$...
    > Hi all!!
    >
    > I need your help.... i'm working since 2 hours on a simple insert

    statement,
    > but couldn't handle it.
    >
    > Here is my code :
    >
    > public int ExecQuery(string SqlString)
    >
    > {
    >
    >
    > OleDbConnection oCoon = new OleDbConnection(connectionString);
    >
    > oCoon.Open();
    >
    > OleDbCommand cmd3 = new OleDbCommand();
    >
    > cmd3.Connection = oCoon;
    >
    > cmd3.CommandText = SqlString;
    >
    > if(oCoon.State == ConnectionState.Closed)
    >
    > {
    >
    > oCoon.Open();
    >
    > }
    >
    > cmd3.ExecuteNonQuery();
    >
    > return 1
    >
    > }
    >
    >
    >
    > When the code reach the cmd3.ExecuteNonQuery(); I always receive the
    > followin error :
    >
    > SYNTAX ERROR IN INSERT INTO STATEMENT....
    >
    > But, i tried to put some debug info (Debug.Write) and my SQL statement

    seem
    > ok.
    >
    >
    >
    > SQL Statement : INSERT INTO COLORS (agent_no,primary,secondary) VALUES
    > (3,'fff','ALLO')
    >
    >
    >
    > Any idea??
    >
    > Thanks,
    >
    >
    William Gower, Jul 31, 2004
    #2
    1. Advertising

  3. eric dugal

    eric dugal Guest

    Thanks, that was the problem!!


    "William Gower" <> a écrit dans le message de
    news:%...
    > primary is a reserved word. Put this instead [primary]
    >
    > "eric dugal" <> wrote in message
    > news:d8POc.113688$...
    > > Hi all!!
    > >
    > > I need your help.... i'm working since 2 hours on a simple insert

    > statement,
    > > but couldn't handle it.
    > >
    > > Here is my code :
    > >
    > > public int ExecQuery(string SqlString)
    > >
    > > {
    > >
    > >
    > > OleDbConnection oCoon = new OleDbConnection(connectionString);
    > >
    > > oCoon.Open();
    > >
    > > OleDbCommand cmd3 = new OleDbCommand();
    > >
    > > cmd3.Connection = oCoon;
    > >
    > > cmd3.CommandText = SqlString;
    > >
    > > if(oCoon.State == ConnectionState.Closed)
    > >
    > > {
    > >
    > > oCoon.Open();
    > >
    > > }
    > >
    > > cmd3.ExecuteNonQuery();
    > >
    > > return 1
    > >
    > > }
    > >
    > >
    > >
    > > When the code reach the cmd3.ExecuteNonQuery(); I always receive the
    > > followin error :
    > >
    > > SYNTAX ERROR IN INSERT INTO STATEMENT....
    > >
    > > But, i tried to put some debug info (Debug.Write) and my SQL statement

    > seem
    > > ok.
    > >
    > >
    > >
    > > SQL Statement : INSERT INTO COLORS (agent_no,primary,secondary) VALUES
    > > (3,'fff','ALLO')
    > >
    > >
    > >
    > > Any idea??
    > >
    > > Thanks,
    > >
    > >

    >
    >
    eric dugal, Aug 1, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. compuglobalhypermeganetz0r

    adapter update problem Syntax error in INSERT INTO statement.

    compuglobalhypermeganetz0r, Dec 8, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    824
    compuglobalhypermeganetz0r
    Dec 8, 2003
  2. Saber
    Replies:
    5
    Views:
    523
    Jo Inferis
    Jul 20, 2004
  3. Neil Zanella
    Replies:
    3
    Views:
    659
    MWells
    Jan 25, 2005
  4. Nathan Sokalski

    SQL syntax error in INSERT INTO statement

    Nathan Sokalski, Jul 1, 2005, in forum: ASP .Net
    Replies:
    5
    Views:
    14,597
    ahmed_samir
    Sep 3, 2010
  5. Gérard Leclercq

    Syntax error in INSERT INTO statement

    Gérard Leclercq, Feb 1, 2005, in forum: ASP General
    Replies:
    6
    Views:
    213
    Bob Barrows [MVP]
    Feb 2, 2005
Loading...

Share This Page