Execute a non-SELECT command

from the Artful MySQL Tips List


The simplest way to do this is via MySqlCommand.ExecuiteNonQuery:
    public int ExecuteNonQuery( string sql ) {
      int ret = -1;
      MySqlCommand cmd = new MySqlCommand();
      try {
        cmd.CommandText = sql;
        cmd.Connection = Connector.Connection;
        ret = cmd.ExecuteNonQuery();
      }
      catch ( MySqlException ex ) {
        this.ErrMsg( ex );
      }
      finally {
        cmd.Dispose();
      }
      return ret;
    }

Last updated 16 Aug 2024


Return to the Artful MySQL Tips page