请教PostgreSQL参数化查询的参数问题

vbman2003 vbman2003 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
示例代码:

'......  
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语句的参数怎么写?谢谢先!
(网上没有到相关资料,郁闷......)



...全文

相关推荐

评论 4
收藏 已收藏
分享
返回顶部
vbman2003
.NET社区 62,272 成员 668,968 内容