SqlCommand - ExecuteDataSet

Executes the query, and returns the result set as DataSet.

Try it

public static void Main()
{
	DataSet result;
    const string sql = @"
SELECT 1
SELECT 2
SELECT 3
";
	
	using (var conn = new SqlConnection(FiddleHelper.GetConnectionStringSqlServer()))
    {
        using (SqlCommand command = conn.CreateCommand())
        {
            conn.Open();
            command.CommandText = sql;
			
			//C# Extension Method: SqlCommand - ExecuteDataSet
            result = command.ExecuteDataSet(); // return DataSet (3 tables).
			conn.Close();
			
			Console.WriteLine(result.Tables.Count);
        }
    }
}

View Source
using System.Data;
using System.Data.SqlClient;

public static partial class Extensions
{
    /// <summary>
    ///     Executes the query, and returns the result set as DataSet.
    /// </summary>
    /// <param name="this">The @this to act on.</param>
    /// <returns>A DataSet that is equivalent to the result set.</returns>
    public static DataSet ExecuteDataSet(this SqlCommand @this)
    {
        var ds = new DataSet();
        using (var dataAdapter = new SqlDataAdapter(@this))
        {
            dataAdapter.Fill(ds);
        }

        return ds;
    }
}