diff --git a/src/Donald/Db.fs b/src/Donald/Db.fs index 2da0e97..3b43fde 100644 --- a/src/Donald/Db.fs +++ b/src/Donald/Db.fs @@ -108,6 +108,13 @@ module Db = tran.TryRollback() reraise () + /// Execute paramterized query and return DataTable + let dataTable (dbUnit : DbUnit) : DataTable = + read (fun rd -> + let dt = new DataTable() + dt.Load(rd) + dt) dbUnit + module Async = let private tryDoAsync (dbUnit : DbUnit) (fn : DbCommand -> Task<'a>) : Task<'a> = task { @@ -165,4 +172,11 @@ module Db = return result } with _ -> tran.TryRollback() - reraise() \ No newline at end of file + reraise() + + /// Asynchronously Execute paramterized query and return DataTable + let dataTable (dbUnit : DbUnit) = + read (fun rd -> + let dt = new DataTable() + dt.Load(rd) + dt) dbUnit \ No newline at end of file diff --git a/src/Donald/Donald.fsproj b/src/Donald/Donald.fsproj index a8f2531..4142aa7 100644 --- a/src/Donald/Donald.fsproj +++ b/src/Donald/Donald.fsproj @@ -2,7 +2,7 @@ Donald - 10.0.2 + 10.1.0 Functional F# interface for ADO.NET. diff --git a/test/Donald.Tests/Tests.fs b/test/Donald.Tests/Tests.fs index ad3ee64..8603fcb 100644 --- a/test/Donald.Tests/Tests.fs +++ b/test/Donald.Tests/Tests.fs @@ -768,3 +768,20 @@ type ExecutionTests() = |> ignore action |> should throw typeof + + [] + member _.``SELECT dataTable should produce DataTable matching first result set`` () = + let sql = " + SELECT 'Donald Chamberlin' AS name, 'Computer Scientist' AS profession + UNION + SELECT 'LeBron James' As name, 'Professional Athlete' AS profession" + + let dataTable = + conn + |> Db.newCommand sql + |> Db.dataTable + + dataTable.Rows[0]["name"] |> should equal "Donald Chamberlin" + dataTable.Rows[0]["profession"] |> should equal "Computer Scientist" + dataTable.Rows[1]["name"] |> should equal "LeBron James" + dataTable.Rows[1]["profession"] |> should equal "Professional Athlete"