I am stuck at the moment trying to find a way to insert into SQL Server from F #.
I have an F # function that iterates through all the files inside the folder following the user template. I can then use the returned data to add to the list or (ideally) insert into the database.
I already have a working insert-in-sql function that works correctly:
let execNonQuery conn s = let comm = new SqlCeCommand(s, conn) try comm.ExecuteNonQuery() |> ignore with e -> printf "Error : %A\n" e let string = "insert into MyTable (MyColumn) values ('test .. again')" execNonQuery conn string; // works
I am trying to make this method work correctly:
let rec getAllFiles dir pattern = seq { yield! Directory.EnumerateFiles(dir, pattern) for d in Directory.EnumerateDirectories(dir) do yield! getAllFiles d pattern } let getApplications (dir : string) (extension : string) = getAllFiles dir extension //|> Seq.toList // If I need to create a list of returned values |> Seq.iter (fun s -> SQLInsertString s) // This does not work as it complains about the function not being of type unit
If I use only Seq.toList and call the function as shown below, it works:
getApplications "C:\Admin" "*.txt" // works
Another thing I don't understand is how you can create a working insert command that takes a string for the value. For instance:
let SQLInsertString s = "insert into MyTable (MyColumn) values (%s)" //does not work
source share