示例代码:'......  
    Dim Sql As String = "select pno from tb where code=$1 "
    Dim cn As NpgsqlConnection = New NpgsqlConnection(cnString)
    cn.Open()    Dim cmd As NpgsqlCommand = New NpgsqlCommand(sql, cn)
    cmd.CommandType = CommandType.Text
    cmd.Parameters.Add(New NpgsqlParameter( _
        "$1", NpgsqlTypes.NpgsqlDbType.Varchar, 6)).Value = "001"    Dim rd As NpgsqlDataReader
    rd = cmd.ExecuteReader
'.......返回错误:
ERROR: 42P02: there is no parameter $1
同样的代码,如果用CommandType.StoredProcedure调用PostgreSQL函数没有问题
请教CommandType.Text下,SQL语句的参数怎么写?谢谢先!
(网上没有到相关资料,郁闷......)

解决方案 »

  1.   

    try:Dim Sql As String = "select pno from tb where code=:Param1 "
    Dim cn As NpgsqlConnection = New NpgsqlConnection(cnString)
    cn.Open()Dim cmd As NpgsqlCommand = New NpgsqlCommand(sql, cn)
    cmd.CommandType = CommandType.Text
    cmd.Parameters.Add(New NpgsqlParameter( _
    ":Param1", NpgsqlTypes.NpgsqlDbType.Varchar, 6)).Value = "001"
      

  2.   

    谢谢BearRui(AK-47)(奋斗目标:农妇,山泉,有点田)和whosyourdaddy(楼主不厚道)二个人的答案都可行,事先我也是用whosyourdaddy(楼主不厚道)的@,死活报错,刚才重新启动一下VS2005又可以了,郁闷.....PostgreSQL的参数好象要用$,可这个在NET下却不行......
    这事我弄了一上午......不能急了