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. General Programming
  3. C#
  4. Incorrect syntax near the keyword 'Transaction'

Incorrect syntax near the keyword 'Transaction'

Scheduled Pinned Locked Moved C#
databasehelp
4 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.
  • H Offline
    H Offline
    haleemasher
    wrote on last edited by
    #1

    i want to insert data into the sql database when i click on submit button it show error that incorrect syntax near the keyword 'Transaction'. i cann't find this error plz help

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
    try
    {

            ErrorMessage.Text = "";
            cnx.Open();
            SqlCommand insertCmd = new SqlCommand("INSERT INTO TransactionType(Transaction,Description,Category,Active) 
    

    VALUES(@Transaction,@Description,@Category,@Active)", cnx);
    insertCmd.Parameters.Add("@Transaction", SqlDbType.NVarChar, 50);
    insertCmd.Parameters["@Transaction"].Value = txtProgram.Text;

            insertCmd.Parameters.Add("@Description", SqlDbType.Text );
            insertCmd.Parameters\["@Description"\].Value = txtdescrip.Text;
    
            insertCmd.Parameters.Add("@Category", SqlDbType.NVarChar ,50);
            insertCmd.Parameters\["@Category"\].Value = DdlCategory.Text;
    
            insertCmd.Parameters.Add("@Active", SqlDbType.NChar ,10);
            insertCmd.Parameters\["@Active"\].Value = DdlActive.Text;
    
            insertCmd.ExecuteNonQuery();
            ErrorMessage.Text = "Successful";
            cnx.Close();
        }
        catch (Exception ex)
        { 
            ErrorMessage.Text = ex.Message;
        }
    }
    
    C M 2 Replies Last reply
    0
    • H haleemasher

      i want to insert data into the sql database when i click on submit button it show error that incorrect syntax near the keyword 'Transaction'. i cann't find this error plz help

      protected void btnSubmit_Click(object sender, EventArgs e)
      {
      try
      {

              ErrorMessage.Text = "";
              cnx.Open();
              SqlCommand insertCmd = new SqlCommand("INSERT INTO TransactionType(Transaction,Description,Category,Active) 
      

      VALUES(@Transaction,@Description,@Category,@Active)", cnx);
      insertCmd.Parameters.Add("@Transaction", SqlDbType.NVarChar, 50);
      insertCmd.Parameters["@Transaction"].Value = txtProgram.Text;

              insertCmd.Parameters.Add("@Description", SqlDbType.Text );
              insertCmd.Parameters\["@Description"\].Value = txtdescrip.Text;
      
              insertCmd.Parameters.Add("@Category", SqlDbType.NVarChar ,50);
              insertCmd.Parameters\["@Category"\].Value = DdlCategory.Text;
      
              insertCmd.Parameters.Add("@Active", SqlDbType.NChar ,10);
              insertCmd.Parameters\["@Active"\].Value = DdlActive.Text;
      
              insertCmd.ExecuteNonQuery();
              ErrorMessage.Text = "Successful";
              cnx.Close();
          }
          catch (Exception ex)
          { 
              ErrorMessage.Text = ex.Message;
          }
      }
      
      C Offline
      C Offline
      Curtis Schlak
      wrote on last edited by
      #2

      In Microsoft SQL Server (and probably any other RDBMS that supports transactions), TRANSACTION is a reserved keyword. Change your SQL to read

      INSERT INTO TransactionType([Transaction],Description,Category,Active)
      VALUES(@Transaction,@Description,@Category,@Active)

      The square brackets indicate a name rather than a keyword.

      "we must lose precision to make significant statements about complex systems." -deKorvin on uncertainty

      H 1 Reply Last reply
      0
      • H haleemasher

        i want to insert data into the sql database when i click on submit button it show error that incorrect syntax near the keyword 'Transaction'. i cann't find this error plz help

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
        try
        {

                ErrorMessage.Text = "";
                cnx.Open();
                SqlCommand insertCmd = new SqlCommand("INSERT INTO TransactionType(Transaction,Description,Category,Active) 
        

        VALUES(@Transaction,@Description,@Category,@Active)", cnx);
        insertCmd.Parameters.Add("@Transaction", SqlDbType.NVarChar, 50);
        insertCmd.Parameters["@Transaction"].Value = txtProgram.Text;

                insertCmd.Parameters.Add("@Description", SqlDbType.Text );
                insertCmd.Parameters\["@Description"\].Value = txtdescrip.Text;
        
                insertCmd.Parameters.Add("@Category", SqlDbType.NVarChar ,50);
                insertCmd.Parameters\["@Category"\].Value = DdlCategory.Text;
        
                insertCmd.Parameters.Add("@Active", SqlDbType.NChar ,10);
                insertCmd.Parameters\["@Active"\].Value = DdlActive.Text;
        
                insertCmd.ExecuteNonQuery();
                ErrorMessage.Text = "Successful";
                cnx.Close();
            }
            catch (Exception ex)
            { 
                ErrorMessage.Text = ex.Message;
            }
        }
        
        M Offline
        M Offline
        Mike Ellison
        wrote on last edited by
        #3

        The error is telling you that you have a problem with your SQL being sent to the database, not with your C# code. Transaction is a reserved word. Try surrounding it with square brackets [Transaction]

        mishainthecloud.blogspot.com

        1 Reply Last reply
        0
        • C Curtis Schlak

          In Microsoft SQL Server (and probably any other RDBMS that supports transactions), TRANSACTION is a reserved keyword. Change your SQL to read

          INSERT INTO TransactionType([Transaction],Description,Category,Active)
          VALUES(@Transaction,@Description,@Category,@Active)

          The square brackets indicate a name rather than a keyword.

          "we must lose precision to make significant statements about complex systems." -deKorvin on uncertainty

          H Offline
          H Offline
          haleemasher
          wrote on last edited by
          #4

          THANK U VERY MUCH ITS WORKS

          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