SQL INSERT syntax error, but the statement is correct!

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • kosta

    SQL INSERT syntax error, but the statement is correct!

    hello! one of my forms communicates with a database, and is
    supposed to add a row to a table using an Insert
    statement... however, I get a 'oledb - syntax error'
    exception... I have double checked, and the insert works
    fine (tried to use it from access)... im using visual C#
    express 2k5... what could be wrong? thanks!
  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: SQL INSERT syntax error, but the statement is correct!

    kosta,

    I would guess that there actually is something wrong with the statement,
    or how you are executing it. Can you show the code that you have which is
    trying to perform the insert?


    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    "kosta" <anonymous@disc ussions.microso ft.com> wrote in message
    news:0b5301c4b2 dd$cedfb360$a30 1280a@phx.gbl.. .[color=blue]
    > hello! one of my forms communicates with a database, and is
    > supposed to add a row to a table using an Insert
    > statement... however, I get a 'oledb - syntax error'
    > exception... I have double checked, and the insert works
    > fine (tried to use it from access)... im using visual C#
    > express 2k5... what could be wrong? thanks![/color]


    Comment

    • Rakesh Rajan

      #3
      RE: SQL INSERT syntax error, but the statement is correct!

      Hi kosta,

      Could you please post the sql statement. Which is the db you are using - is
      it access?

      Regards,
      Rakesh Rajan

      "kosta" wrote:
      [color=blue]
      > hello! one of my forms communicates with a database, and is
      > supposed to add a row to a table using an Insert
      > statement... however, I get a 'oledb - syntax error'
      > exception... I have double checked, and the insert works
      > fine (tried to use it from access)... im using visual C#
      > express 2k5... what could be wrong? thanks!
      >[/color]

      Comment

      • Ignacio Machin \( .NET/ C#  MVP \)

        #4
        Re: SQL INSERT syntax error, but the statement is correct!

        Hi,

        Probably you have a ' somewhere used as a parameter, for any further help
        post the code and the exception message

        cheers,

        --
        Ignacio Machin,
        ignacio.machin AT dot.state.fl.us
        Florida Department Of Transportation



        "kosta" <anonymous@disc ussions.microso ft.com> wrote in message
        news:0b5301c4b2 dd$cedfb360$a30 1280a@phx.gbl.. .[color=blue]
        > hello! one of my forms communicates with a database, and is
        > supposed to add a row to a table using an Insert
        > statement... however, I get a 'oledb - syntax error'
        > exception... I have double checked, and the insert works
        > fine (tried to use it from access)... im using visual C#
        > express 2k5... what could be wrong? thanks![/color]


        Comment

        • kosta

          #5
          RE: SQL INSERT syntax error, but the statement is correct!

          Yes, it is an access 2000 database.
          here is the statement:

          INSERT INTO Partyers (Sex, Last, First, CPhone, Phone,
          City, BDay, Car, PicPath, FPotential, TPotential,
          PartyCities) Values (False, '', '', '', '', '', '10/16/2004
          12:17:22 AM', False, '', '', '', '')

          when I use it from access, it goes file...

          here is the code I use to Add it:

          public static int ANum(String sql)
          {
          OleDbConnection con = new OleDbConnection ();
          con.ConnectionS tring =
          ConfigurationSe ttings.AppSetti ngs["conString"];
          OleDbCommand cmd = new OleDbCommand(sq l,con);
          con.Open();
          cmd.ExecuteNonQ uery();
          string identity = "select @@identity";
          cmd.CommandText = identity;
          int id = (int)cmd.Execut eScalar();
          con.Close();
          return id;
          }

          and the exception:


          {"Syntax error in INSERT INTO statement."}
          [System.Data.Ole Db.OleDbExcepti on]: {"Syntax error in
          INSERT INTO statement."}
          Data: {System.Collect ions.ListDictio naryInternal}
          HelpLink: null
          InnerException: null
          Message: "Syntax error in INSERT INTO statement."
          Source: "Microsoft JET Database Engine"
          StackTrace: " at
          System.Data.Ole Db.OleDbCommand .ExecuteCommand TextErrorHandli ng(OleDbHResult
          hr)\r\n at
          System.Data.Ole Db.OleDbCommand .ExecuteCommand TextForSingleRe sult(tagDBPARAM S
          dbParams, Object& executeResult)\ r\n at
          System.Data.Ole Db.OleDbCommand .ExecuteCommand Text(Object&
          executeResult)\ r\n at
          System.Data.Ole Db.OleDbCommand .ExecuteCommand (CommandBehavio r
          behavior, Object& executeResult)\ r\n at
          System.Data.Ole Db.OleDbCommand .ExecuteReaderI nternal(Command Behavior
          behavior, String method)\r\n at
          System.Data.Ole Db.OleDbCommand .ExecuteNonQuer y()\r\n at
          SQL.Connect.ANu m(String sql) in f:\\my documents\\visu al
          studio\\project s\\connect\\con nect.cs:line 63\r\n at
          SQLStatements.P artiesDB.AddPar tier(Boolean Sex, String
          LName, String FName, String CPhone, String Phone, String
          City, DateTime BDay, Boolean Car, String PicPath, String
          PotentialClient , String PotentialTrippe r, String PCities)
          in f:\\my documents\\visu al
          studio\\project s\\sqlstatement s\\partiersdb.c s:line 20\r\n
          at DataBase.Partye r
          Update.Add() in F:\\My Documents\\Visu al
          Studio\\Project s\\Database\\Pa rtyerUpdate.cs: line 35"
          TargetSite: {Void
          ExecuteCommandT extErrorHandlin g(System.Data.O leDb.OleDbHResu lt)}


          thanks a lot in advance! (and to those that already responded!)
          Kosta.
          [color=blue]
          >-----Original Message-----
          >Hi kosta,
          >
          >Could you please post the sql statement. Which is the db[/color]
          you are using - is [color=blue]
          >it access?
          >
          >Regards,
          >Rakesh Rajan
          >
          >"kosta" wrote:
          >[color=green]
          >> hello! one of my forms communicates with a database, and is
          >> supposed to add a row to a table using an Insert
          >> statement... however, I get a 'oledb - syntax error'
          >> exception... I have double checked, and the insert works
          >> fine (tried to use it from access)... im using visual C#
          >> express 2k5... what could be wrong? thanks!
          >> [/color]
          >.
          >[/color]

          Comment

          • kosta

            #6
            RE: SQL INSERT syntax error, but the.

            it is an access 2000 database.
            here is the statement:

            INSERT INTO Partyers (Sex, Last, First, CPhone, Phone,
            City, BDay, Car, PicPath, FPotential, TPotential,
            PartyCities) Values (False, '', '', '', '', '', '10/16/2004
            12:17:22 AM', False, '', '', '', '')

            when I use it from access, it goes file...

            here is the code I use to Add it:

            public static int ANum(String sql)
            {
            OleDbConnection con = new OleDbConnection ();
            con.ConnectionS tring =
            ConfigurationSe ttings.AppSetti ngs["conString"];
            OleDbCommand cmd = new OleDbCommand(sq l,con);
            con.Open();
            cmd.ExecuteNonQ uery();
            string identity = "select @@identity";
            cmd.CommandText = identity;
            int id = (int)cmd.Execut eScalar();
            con.Close();
            return id;
            }

            and the exception:


            {"Syntax error in INSERT INTO statement."}
            [System.Data.Ole Db.OleDbExcepti on]: {"Syntax error in
            INSERT INTO statement."}
            Data: {System.Collect ions.ListDictio naryInternal}
            HelpLink: null
            InnerException: null
            Message: "Syntax error in INSERT INTO statement."
            Source: "Microsoft JET Database Engine"
            StackTrace: " at
            System.Data.Ole Db.OleDbCommand .ExecuteCommand TextErrorHandli ng(OleDbHResult
            hr)\r\n at
            System.Data.Ole Db.OleDbCommand .ExecuteCommand TextForSingleRe sult(tagDBPARAM S
            dbParams, Object& executeResult)\ r\n at
            System.Data.Ole Db.OleDbCommand .ExecuteCommand Text(Object&
            executeResult)\ r\n at
            System.Data.Ole Db.OleDbCommand .ExecuteCommand (CommandBehavio r
            behavior, Object& executeResult)\ r\n at
            System.Data.Ole Db.OleDbCommand .ExecuteReaderI nternal(Command Behavior
            behavior, String method)\r\n at
            System.Data.Ole Db.OleDbCommand .ExecuteNonQuer y()\r\n at
            SQL.Connect.ANu m(String sql) in f:\\my documents\\visu al
            studio\\project s\\connect\\con nect.cs:line 63\r\n at
            SQLStatements.P artiesDB.AddPar tier(Boolean Sex, String
            LName, String FName, String CPhone, String Phone, String
            City, DateTime BDay, Boolean Car, String PicPath, String
            PotentialClient , String PotentialTrippe r, String PCities)
            in f:\\my documents\\visu al
            studio\\project s\\sqlstatement s\\partiersdb.c s:line 20\r\n
            at DataBase.Partye r
            Update.Add() in F:\\My Documents\\Visu al
            Studio\\Project s\\Database\\Pa rtyerUpdate.cs: line 35"
            TargetSite: {Void
            ExecuteCommandT extErrorHandlin g(System.Data.O leDb.OleDbHResu lt)}


            thanks a lot in advance! (and to those that already responded!)
            Kosta.[color=blue]
            >-----Original Message-----
            >Message unavailable[/color]

            Comment

            • Guest's Avatar

              #7
              Re: SQL INSERT syntax error, but the statement is correct!

              it is an access 2000 database.
              here is the statement:

              INSERT INTO Partyers (Sex, Last, First, CPhone, Phone,
              City, BDay, Car, PicPath, FPotential, TPotential,
              PartyCities) Values (False, '', '', '', '', '', '10/16/2004
              12:17:22 AM', False, '', '', '', '')

              when I use it from access, it goes file...

              here is the code I use to Add it:

              public static int ANum(String sql)
              {
              OleDbConnection con = new OleDbConnection ();
              con.ConnectionS tring =
              ConfigurationSe ttings.AppSetti ngs["conString"];
              OleDbCommand cmd = new OleDbCommand(sq l,con);
              con.Open();
              cmd.ExecuteNonQ uery();
              string identity = "select @@identity";
              cmd.CommandText = identity;
              int id = (int)cmd.Execut eScalar();
              con.Close();
              return id;
              }

              and the exception:


              {"Syntax error in INSERT INTO statement."}
              [System.Data.Ole Db.OleDbExcepti on]: {"Syntax error in
              INSERT INTO statement."}
              Data: {System.Collect ions.ListDictio naryInternal}
              HelpLink: null
              InnerException: null
              Message: "Syntax error in INSERT INTO statement."
              Source: "Microsoft JET Database Engine"
              StackTrace: " at
              System.Data.Ole Db.OleDbCommand .ExecuteCommand TextErrorHandli ng(OleDbHResult
              hr)\r\n at
              System.Data.Ole Db.OleDbCommand .ExecuteCommand TextForSingleRe sult(tagDBPARAM S
              dbParams, Object& executeResult)\ r\n at
              System.Data.Ole Db.OleDbCommand .ExecuteCommand Text(Object&
              executeResult)\ r\n at
              System.Data.Ole Db.OleDbCommand .ExecuteCommand (CommandBehavio r
              behavior, Object& executeResult)\ r\n at
              System.Data.Ole Db.OleDbCommand .ExecuteReaderI nternal(Command Behavior
              behavior, String method)\r\n at
              System.Data.Ole Db.OleDbCommand .ExecuteNonQuer y()\r\n at
              SQL.Connect.ANu m(String sql) in f:\\my documents\\visu al
              studio\\project s\\connect\\con nect.cs:line 63\r\n at
              SQLStatements.P artiesDB.AddPar tier(Boolean Sex, String
              LName, String FName, String CPhone, String Phone, String
              City, DateTime BDay, Boolean Car, String PicPath, String
              PotentialClient , String PotentialTrippe r, String PCities)
              in f:\\my documents\\visu al
              studio\\project s\\sqlstatement s\\partiersdb.c s:line 20\r\n
              at DataBase.Partye r
              Update.Add() in F:\\My Documents\\Visu al
              Studio\\Project s\\Database\\Pa rtyerUpdate.cs: line 35"
              TargetSite: {Void
              ExecuteCommandT extErrorHandlin g(System.Data.O leDb.OleDbHResu lt)}


              thanks a lot in advance! (and to those that already responded!)
              Kosta.[color=blue]
              >-----Original Message-----
              >kosta,
              >
              > I would guess that there actually is something wrong[/color]
              with the statement, [color=blue]
              >or how you are executing it. Can you show the code that[/color]
              you have which is [color=blue]
              >trying to perform the insert?
              >
              >
              >--
              > - Nicholas Paldino [.NET/C# MVP]
              > - mvp@spam.guard. caspershouse.co m
              >
              >"kosta" <anonymous@disc ussions.microso ft.com> wrote in[/color]
              message [color=blue]
              >news:0b5301c4b 2dd$cedfb360$a3 01280a@phx.gbl. ..[color=green]
              >> hello! one of my forms communicates with a database, and is
              >> supposed to add a row to a table using an Insert
              >> statement... however, I get a 'oledb - syntax error'
              >> exception... I have double checked, and the insert works
              >> fine (tried to use it from access)... im using visual C#
              >> express 2k5... what could be wrong? thanks! [/color]
              >
              >
              >.
              >[/color]

              Comment

              • Joep

                #8
                Re: SQL INSERT syntax error, but the.

                What happens if you pass a null date instead?


                Comment

                Working...