我有以下代碼來獲取CSV文件的類型信息。如何獲取列的類型信息?我將需要將其保存到數據庫表中。從CsvProvider獲取列類型信息?
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 able`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 able`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
....
附註:如果你是從你的類型提供者提供的相同文件加載,你可以直接調用'的getSample()',而不是'負載(「文件名」)' –
大。 'GetSample()'在這種情況下是很好的。 – ca9163d9