I have a SQL Server CE database that I'm trying to update with values from an event, however when I try to do insert from the event observable, the console prints out
< null >
Does anyone know why this is?
Code that works outside observable:
let test1 =
use con = new SqlCeConnection (@"Data Source=C:\Users\Database1.sdf")
con.Open()
let AA = "Enter"
let BB = "Enter"
use cmd = new SqlCeCommand("insert into Table1 (A,B) values (@A, @B)", con)
let A1 = new SqlCeParameter("A", "1")
let B1 = new SqlCeParameter("B", "2")
do cmd.Parameters.Add A1 |>ignore
do cmd.Parameters.Add B1 |>ignore
do cmd.ExecuteNonQuery() |>ignore
printfn "%s" "complete1"
()
Code that returns < null > , also to note the printfn at the end does not execute.
let sqlsubmit = stream|> Observable.map (fun x ->
use con = new SqlCeConnection (@"Data Source=C:\Users\Database1.sdf")
con.Open()
let AA = "Enter"
let BB = "Enter"
use cmd = new SqlCeCommand("insert into Table1 (A,B) values (@A, @B)", con)
let A1 = new SqlCeParameter("A", "1")
let B1 = new SqlCeParameter("B", "2")
do cmd.Parameters.Add A1 |>ignore
do cmd.Parameters.Add B1 |>ignore
do cmd.ExecuteNonQuery |>ignore
printfn "%s" "complete1"
)
I've tried SubmitChanges()
from Linq, and it does the same.
Here's the type used for the LINQ SubmitChanges:
[<Table(Name = "Table1")>]
type Macro (A:string, B:string)=
[<Column(IsPrimaryKey=true)>]
member this.A = A
[<Column>]
member this.B = B
The unit
type in F# is a singleton type; it's value is specified by ()
.
The ()
value is represented by a null
within the compiled code, which is why you see your code return null
.