Note that there are some explanatory texts on larger screens.

plurals
  1. POF# insert a list into SQL Server
    primarykey
    data
    text
    <p>I'm stuck at the moment trying to figure out a method of inserting into SQL Server from F#.</p> <p>I have an F# function that iterates through all files inside a folder following a user-defined pattern. Then I can use the returned data to put in a list or (ideally) insert into a database.</p> <p>I already have a working insert-into-sql function that works properly:</p> <pre class="lang-ml prettyprint-override"><code>let execNonQuery conn s = let comm = new SqlCeCommand(s, conn) try comm.ExecuteNonQuery() |&gt; ignore with e -&gt; printf "Error : %A\n" e let string = "insert into MyTable (MyColumn) values ('test .. again')" execNonQuery conn string; // works </code></pre> <p>I'm trying to get this method to work properly:</p> <pre class="lang-ml prettyprint-override"><code>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 //|&gt; Seq.toList // If I need to create a list of returned values |&gt; Seq.iter (fun s -&gt; SQLInsertString s) // This does not work as it complains about the function not being of type unit </code></pre> <p>If I use <code>Seq.toList</code> only and call the function as per below, it works:</p> <pre class="lang-ml prettyprint-override"><code>getApplications "C:\Admin" "*.txt" // works </code></pre> <p>The other thing I don't understand is how can you create a working insert command that takes in a string for Value. For example: </p> <pre class="lang-ml prettyprint-override"><code>let SQLInsertString s = "insert into MyTable (MyColumn) values (%s)" //does not work </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload