© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
25 replies
Xantres

MySql Syntax error

I am creating a method that will take in an object with properties that have data that is needed for the DB Update. I am getting an error
that is included in a screen shot. Here is my code:
public static void UpdateCustomerName(Customer customer)
{
  string updateName = $"UPDATE client_schedule.customer SET customerName = '{customer.CustomerName}'" +
      $"WHERE customerId = {customer.CustomerID}";
  
  DBConnect.StartConnection(); // Starts the connection
  
  try
  {
    using (DBConnect.Conn)
      using (MySqlCommand cmd = new MySqlCommand(updateName, DBConnect.Conn))
      {
        cmd.ExecuteNonQuery();
      }
    }
  }
  catch (MySqlException ex) 
  {
    DBConnect.StopConnection();
    
    MessageBox.Show(ex.Message);
  }

  DBConnect.StopConnection();
}
public static void UpdateCustomerName(Customer customer)
{
  string updateName = $"UPDATE client_schedule.customer SET customerName = '{customer.CustomerName}'" +
      $"WHERE customerId = {customer.CustomerID}";
  
  DBConnect.StartConnection(); // Starts the connection
  
  try
  {
    using (DBConnect.Conn)
      using (MySqlCommand cmd = new MySqlCommand(updateName, DBConnect.Conn))
      {
        cmd.ExecuteNonQuery();
      }
    }
  }
  catch (MySqlException ex) 
  {
    DBConnect.StopConnection();
    
    MessageBox.Show(ex.Message);
  }

  DBConnect.StopConnection();
}
image.png
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ syntax error
C#CC# / help
2y ago
✅ Syntax Error
C#CC# / help
2y ago
mysql error
C#CC# / help
12mo ago
mysql connect error
C#CC# / help
2y ago