Using the MySql ADO.Net adapter

public DataSet ExecuteQuery(string commandText)
        {
            DataSet ds = new DataSet();
            using (var connection = new MySqlConnection(connString))
            {
                connection.Open();
                var command = connection.CreateCommand();
                command.CommandText = commandText;
                using (var data = new MySqlDataAdapter { SelectCommand = command })
                {
                    data.Fill(ds);
                    connection.Close();
                }
            }
            return ds;
        }

Leave a Reply