Is it possible to build a DataTable object from scratch using F#
I have written this code
module DataHelper
open System
open System.Data
open System.Data.SqlClient
let addDataRow (dt : DataTable) kerberos =
let dr = dt.NewRow()
dr["Kerberos"] = kerberos
dt.Rows.Add(dr)
let Func userList : string seq =
let dt : DataTable = new DataTable("UserNameListType")
let dc : DataColumn = new DataColumn("Kerberos")
dt.Columns.Add(dc)
Seq.iter (fun user -> addDataRow dt user) userList
dt
But this has too many errors
- VS.NET does not seem to understand DataTable, DataRow classes and only shows me a “Note” as intellisense.
- Its hard to use the collection objects Rows, Columns in F# because none of the methods really work (which work easily in C#).
If you’re doing this in a new project, you need to add references to
System.Data.dllandSystem.Xml.dll. After that, Visual Studio should recognize the types. You can do that by right clicking on “References” in your project and choosing “Add Reference”.Aside from that, there are two minor mistakes in your code. The assignment should be written as (note that there is a dot before
[and the operator is<-instead of=):And your
Funcfunction should returnDataTable: