title: Check if table creation was successful
body: <p>I have a Winforms app that has to migrate data from SQL to MySQL. Part of the functionality requires preparing the target database by adding the required tables (and dropping existing tables if necessary).</p>
  
  <p>I'm looking for the most efficient way to determine if the table was created successfully. <a href="https://stackoverflow.com/questions/24061615/how-to-detect-if-a-mysql-query-was-successful-or-not-and-output-a-message">This question's answer</a> suggested that executing the query would return an integer value greater than 0 if it was successful. Ideally, I'd like to execute the command and use a return value rather than running another query. Is this possible? </p>
  
  <p>My current code:</p>
  
  <pre><code>MySqlConnection myConnection = new MySqlConnection(ConnectionString);
  string sql = @" DROP TABLE IF EXISTS    `sf_root_items`;
                  CREATE TABLE            `sf_root_items` (
                                          `ID` varchar(255) NOT NULL,
                                          `LoweredName` varchar(255) DEFAULT NULL,
                                          `MenuName` varchar(255) DEFAULT NULL,
                                          `Title` varchar(255) DEFAULT NULL,
                                          `Description` varchar(255) DEFAULT NULL,
                                          `PageType` varchar(255) DEFAULT NULL,
                                          `ExternalUrl` varchar(255) DEFAULT NULL,
                                          PRIMARY KEY(`ID`)
                                          )";
  MySqlCommand cmd;
  try
  {
      if (myConnection.State != ConnectionState.Open)
      {
          myConnection.Close();
          myConnection.Open();
      }
      cmd = myConnection.CreateCommand();
      cmd.CommandText = sql;
      int output = cmd.ExecuteNonQuery();
  
      // a value greater than 0 means execution was successful
      if (output &gt; 0)
      {
          DBPrepDone = "Table created";
      }
      else
      {
          DBPrepDone = "There was an error";
      }
  
      myConnection.Close();
  }
  catch (Exception ex)
  {
      DBPrepDone = ex.ToString();
  }
  </code></pre>