Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. exception: Missing semicolon (;) at end of SQL statement [modified]

exception: Missing semicolon (;) at end of SQL statement [modified]

Scheduled Pinned Locked Moved ASP.NET
databasehelp
8 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    benams
    wrote on last edited by
    #1

    I'm using msaccess(2007) database and I get the error message above while tryig to execute the following code:

    OleDbCommand cmd = new OleDbCommand();
    cmd.CommandText = "INSERT INTO tblCategory(CategoryName, OrderNum) " +
                      "VALUES(@CategoryName, @OrderNum) " +
                      "SELECT @@IDENTITY AS ID";
    cmd.Parameters.Add(new OleDbParameter("@CategoryName", Category.CategoryName));
    cmd.Parameters.Add(new OleDbParameter("@OrderNum", Category.Order));
    cmd.Connection = DataAccess.CreateConnection("Malasot", false);
    DataTable dt = new DataTable();
    OleDbDataAdapter adapter = new OleDbDataAdapter(cmd);
    
    if(cmd.Connection.State != ConnectionState.Open)
       cmd.Connection.Open();
    
    adapter.Fill(dt); // \*\*\*the exception occurs here.\*\*\*
    

    note: I have tryed putting semicolon between the 2 statements and it doesn't solve the problem.

    modified on Monday, June 20, 2011 2:38 PM

    P 1 Reply Last reply
    0
    • B benams

      I'm using msaccess(2007) database and I get the error message above while tryig to execute the following code:

      OleDbCommand cmd = new OleDbCommand();
      cmd.CommandText = "INSERT INTO tblCategory(CategoryName, OrderNum) " +
                        "VALUES(@CategoryName, @OrderNum) " +
                        "SELECT @@IDENTITY AS ID";
      cmd.Parameters.Add(new OleDbParameter("@CategoryName", Category.CategoryName));
      cmd.Parameters.Add(new OleDbParameter("@OrderNum", Category.Order));
      cmd.Connection = DataAccess.CreateConnection("Malasot", false);
      DataTable dt = new DataTable();
      OleDbDataAdapter adapter = new OleDbDataAdapter(cmd);
      
      if(cmd.Connection.State != ConnectionState.Open)
         cmd.Connection.Open();
      
      adapter.Fill(dt); // \*\*\*the exception occurs here.\*\*\*
      

      note: I have tryed putting semicolon between the 2 statements and it doesn't solve the problem.

      modified on Monday, June 20, 2011 2:38 PM

      P Offline
      P Offline
      Parwej Ahamad
      wrote on last edited by
      #2

      as your error stating, just place semi colon after the insert statement.

      cmd.CommandText = "INSERT INTO tblCategory(CategoryName, OrderNum) " +
      "VALUES(@CategoryName, @OrderNum); " +
      "SELECT @@IDENTITY AS ID";

      Parwej Ahamad ahamad.parwej@gmail.com

      B 1 Reply Last reply
      0
      • P Parwej Ahamad

        as your error stating, just place semi colon after the insert statement.

        cmd.CommandText = "INSERT INTO tblCategory(CategoryName, OrderNum) " +
        "VALUES(@CategoryName, @OrderNum); " +
        "SELECT @@IDENTITY AS ID";

        Parwej Ahamad ahamad.parwej@gmail.com

        B Offline
        B Offline
        benams
        wrote on last edited by
        #3

        I've just tryed it, it didn't help

        A P 2 Replies Last reply
        0
        • B benams

          I've just tryed it, it didn't help

          A Offline
          A Offline
          AspDotNetDev
          wrote on last edited by
          #4

          How about adding a semicolon after the second SQL statement:

          cmd.CommandText =
          "INSERT INTO tblCategory(CategoryName, OrderNum) " +
          "VALUES(@CategoryName, @OrderNum); " +
          "SELECT @@IDENTITY AS ID;";

          Help a brotha out and vote Managing Your JavaScript Library in ASP.NET as the best ASP.NET article of May 2011.

          1 Reply Last reply
          0
          • B benams

            I've just tryed it, it didn't help

            P Offline
            P Offline
            Parwej Ahamad
            wrote on last edited by
            #5

            Error is same OR giving different one? Can you try once to execute two separate statement on by one because I have double that Access generating instantly Identity value. Thanks, Parwej

            Parwej Ahamad ahamad.parwej@gmail.com

            B 1 Reply Last reply
            0
            • P Parwej Ahamad

              Error is same OR giving different one? Can you try once to execute two separate statement on by one because I have double that Access generating instantly Identity value. Thanks, Parwej

              Parwej Ahamad ahamad.parwej@gmail.com

              B Offline
              B Offline
              benams
              wrote on last edited by
              #6

              I've tryed adding semicolon and the error message I get is: "Characters found after end of SQL statement." I guess it will work well if I execute 2 seperated commands, but my goal is to execute all in one command, if it's possible.

              P 1 Reply Last reply
              0
              • B benams

                I've tryed adding semicolon and the error message I get is: "Characters found after end of SQL statement." I guess it will work well if I execute 2 seperated commands, but my goal is to execute all in one command, if it's possible.

                P Offline
                P Offline
                Parwej Ahamad
                wrote on last edited by
                #7

                Hi Benames, I haven't try from side, but I had searched on Google and they clearly mentioned that we can not execute multiple statement in single query against Ms Access DB. So may be cause of the error. So if possible execute two separated statement to achieve your goal. Thanks, Parwej

                Parwej Ahamad ahamad.parwej@gmail.com

                B 1 Reply Last reply
                0
                • P Parwej Ahamad

                  Hi Benames, I haven't try from side, but I had searched on Google and they clearly mentioned that we can not execute multiple statement in single query against Ms Access DB. So may be cause of the error. So if possible execute two separated statement to achieve your goal. Thanks, Parwej

                  Parwej Ahamad ahamad.parwej@gmail.com

                  B Offline
                  B Offline
                  benams
                  wrote on last edited by
                  #8

                  Ok, probably you are right. It goes well when I run it in 2 different commands.

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups