小编cor*_*yn3的帖子

使常量成为从F#中的函数生成的字符串

我是F#的新手,我一直在从这个问题中脱颖而出:

SqlCommandProvider需要一个常量字符串,以下函数无法提供该字符串。在F#交互式中运行它会返回“这不是有效的常量表达式或自定义属性值。”

let textgen (RIC: string, price: float, volume: int, inst: int, time:string) =
    let mutable mystring = "INSERT INTO hsbc(RIC, price, volume, type, time) VALUES (st1, st2, st3, st4, st5)"
    mystring <- mystring.Replace ("st1", RIC)
    mystring <- mystring.Replace ("st2", price.ToString())
    mystring <- mystring.Replace ("st3", volume.ToString())
    mystring <- mystring.Replace ("st4", inst.ToString())
    mystring <- mystring.Replace ("st5", time)
    mystring


let sqlcommand1 = textgen("0005.hk",71.2,5000,1,"2019-07-18 10:34:09.193")

type writedata4=SqlCommandProvider<sqlcommand1,connStr>
do
    let cmd6 = new writedata4(connStr)
    cmd6.Execute()
    0
Run Code Online (Sandbox Code Playgroud)

我已经进行了一些研究,并且知道这是sqlcommand1在编译期间不是常量的问题。所以我尝试了这个:

[<Literal>]
let sqlcommand1 = textgen("0005.hk",71.2,5000,1,"2019-07-18 10:34:09.193")
Run Code Online (Sandbox Code Playgroud)

再次返回:“这不是有效的常量表达式或自定义属性值” …

f#

1
推荐指数
1
解决办法
71
查看次数

标签 统计

f# ×1