我有以下代码来获取 CSV 文件的类型信息。如何获取列的类型信息?我需要将它保存到数据库表中。
open FSharp.Data
type MyFile = CsvProvider<"""C:\temp\sample.csv""">
[<EntryPoint>]
let main argv =
let myFile = MyFile.Load("""C:\temp\sample.csv""")
printfn "%A" ((myFile.Rows |> Seq.head).GetType())
// Write the type information of myFile columns to a table
for row in myFile.Rows do
printfn "%A" row
0
函数((myFile.Rows |> Seq.head).GetType()) 返回基本 F# 类型的嵌入元组,并且缺少标头名称。
System.Tuple`8[System.Int32,System.Int32,System.String,System.Int32,System.Int32
,System.String,System.String,System.Tuple`8[System.Int32,System.String,System.De
cimal,System.Decimal,System.Decimal,System.Decimal,System.Int32,System.Tuple`8[S
ystem.Decimal,System.Decimal,System.Decimal,System.Nullable`1[System.Int32],Syst
em.String,System.Boolean,System.Int32,System.Tuple`8[System.Decimal,System.Int32
,System.Int32,System.Decimal,System.Int32,System.Nullable`1[System.Int32],System
.Int32,System.Tuple`8[System.Decimal,System.Nullable`1[System.Int32],System.Null
能够`1[System.Int32],System.Nullable`1[System.Int32],System.Decimal,System.Decim
al,System.String,System.Tuple`8[System.String,System.String,System.String,System
.String,System.String,System.String,System.String,System.Tuple`8[System.String,S
ystem.String,System.String,System.String,System.String,System.String,System.Null
能够`1[System.Int32],System.Tuple`8[System.String,System.String,System.Nullable`
1[System.Int32],System.String,System.String,System.String,System.String,System.T
uple`8[System.String,System.String,System.String,System.String,System.String,Sys
tem.String,System.String,System.Tuple`1[System.String]]]]]]]]]]
预期输出,
ColumnA int
ColumnB datetime
ColumnC varchar
....