Execute a query, return a DataTable

from the Artful MySQL Tips List


This method assumes a MySqlConnection object named Conn in the current scope. Adjust it to suit your needs.

    public DataTable QueryResult( string qry ) {
      MySqlDataAdapter da;
      MySqlCommandBuilder cb;
      DataTable dt = new DataTable();
      try {
        da = new MySqlDataAdapter( qry, Conn );
        cb = new MySqlCommandBuilder( da );
        da.Fill( dt );
      }
      catch ( MySqlException ex ) {
        ErrMsg( ex );
      }
      return dt;
    }




Return to the Artful MySQL Tips page