title: mysterious error in MySQL INSERT INTO Query using asp.net c#
body: <p>I'm trying to find an error in my MySQL query for quite too long now. All I want to do is to insert a couple of values into my database. The query works fine as long as I do NOT include the value for <strong>"longText"</strong> and I have absolutely now idea what causes a problem  with this easy simple query. </p>
  
  <p>Here is the MySQL Exception Message:</p>
  
  <pre><code>MySql.Data.MySqlClient.MySqlException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'longText) VALUES ('191', '529', '', '1', 'index', CURRENT_TIMESTAMP, ' at line 1
  
  Zeile 548:        cmd.Connection = con;
  Zeile 549:        cmd.CommandText = "INSERT INTO confirmationfreetext (confirmationId, customer, shortText, sorting, addedBy, entryDate, longText) VALUES (@confirmationId, @customer, @shortText, @sorting, @addedBy, CURRENT_TIMESTAMP, @longText)";
  Zeile 550:        cmd.ExecuteNonQuery();
  Zeile 551:        con.Close();
  
  [MySqlException (0x80004005): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'longText) VALUES ('191', '529', '', '1', 'index', CURRENT_TIMESTAMP, ' at line 1]
     MySql.Data.MySqlClient.MySqlStream.ReadPacket() +275
     MySql.Data.MySqlClient.NativeDriver.GetResult(Int32&amp; affectedRow, Int32&amp; insertedId) +116
     MySql.Data.MySqlClient.Driver.GetResult(Int32 statementId, Int32&amp; affectedRows, Int32&amp; insertedId) +54
     MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId) +132
     MySql.Data.MySqlClient.MySqlDataReader.NextResult() +707
     MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior) +1620
     MySql.Data.MySqlClient.MySqlCommand.ExecuteReader() +37
     MySql.Data.MySqlClient.MySqlCommand.ExecuteNonQuery() +58
     editConfirmation.saveFreeTextButton_Click(Object sender, EventArgs e) in e:\aspnet_projects\ammon\editConfirmation.aspx.cs:550
     System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9614758
     System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +103
     System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
     System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
     System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35
     System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1724
  </code></pre>
  
  <p>This is the related asp.net c# code:</p>
  
  <pre><code>        //connect to database
          MySqlConnection con = new MySqlConnection();
          con.ConnectionString = Helper.CONNECTION_STRING;
          MySqlCommand cmd = null;
  
          //add freetext to db
          con.Open();
          cmd = new MySqlCommand();
          cmd.Parameters.AddWithValue("@confirmationId", Session["currentConfirmationId"].ToString());
          cmd.Parameters.AddWithValue("@customer", Session["currentCustomerId"].ToString());
          cmd.Parameters.AddWithValue("@shortText", shortText.Text);
          cmd.Parameters.AddWithValue("@longText", longText.Text);
          cmd.Parameters.AddWithValue("@sorting", "1");
          cmd.Parameters.AddWithValue("@addedBy", Session["authenticatedUser"].ToString());
          cmd.Parameters.AddWithValue("@entryDate", "CURRENT_TIMESTAMP");
          cmd.Connection = con;
          cmd.CommandText = "INSERT INTO confirmationfreetext (confirmationId, customer, shortText, sorting, addedBy, entryDate, longText) VALUES (@confirmationId, @customer, @shortText, @sorting, @addedBy, CURRENT_TIMESTAMP, @longText)";
          cmd.ExecuteNonQuery();
          con.Close();
  </code></pre>
  
  <p>I can change the value to </p>
  
  <pre><code>cmd.Parameters.AddWithValue("@longText", 'blablabla');
  </code></pre>
  
  <p>or whatever I want, I always get the same error. I also get the same error if I write the value manually into my MySQL query. </p>
  
  <p>Here is the related MySQL Table:</p>
  
  <pre><code>CREATE  TABLE `ammon`.`confirmationfreetext` (
    `id` INT NOT NULL AUTO_INCREMENT ,
    `confirmationId` INT NULL ,
    `customer` INT(11) NULL ,
    `shortText` VARCHAR(255) NULL ,
    `longText` VARCHAR(255) NULL ,
    `sorting` INT NULL ,
    `entryDate` TIMESTAMP NULL DEFAULT '0000-00-00 00:00:00' ,
    `addedBy` VARCHAR(128) NULL ,
    PRIMARY KEY (`id`) );
  </code></pre>
  
  <p>I hope anyone can say something about this error. Thx in advance. </p>