Reputation: 11
I wonder if this approach (setting properties) is supposed to work. I am getting FS0001 (This expression was expected to have type ''a-> 'b' but here has type 'SqlConnection') on the line 17 (cmd.Connection <| conn) and the same for string for the line 18 (cmd.CommandText <| "select getdate() as d"). Code snippet:
open System
open System.Data
open System.Data.SqlClient
[<Literal>]
let ConnectionString = @"Data Source=(local);Initial Catalog=master;Integrated Security=True"
[<EntryPoint>]
let main argv =
let conn = new SqlConnection(ConnectionString)
conn.Open()
let cmd = new SqlCommand()
cmd.Connection <| conn
cmd.CommandText <| "select getdate() as d"
let da = new SqlDataAdapter(cmd)
let ds = new DataSet()
da.Fill ds |> ignore
printfn "result is"
0
I was able to get data from database using other libraries. What I would like to achieve in addition is to be able to translate C# code used in many places to F# without having to add specific dependencies (to just overcome the type inference issues).
Many thanks, Alex
Upvotes: 0
Views: 71
Reputation: 11
as Fyodor Soiking and Travis (comments) have pointed out a simple syntax issue was actually the problem.
Correct approach to assign a property is to use "<-" instead of "<|".
Thanks a lot! Alex
Upvotes: 1