PostgreSQL:VB.NET ODBC UPDATE无法正常工作

时间:2019-07-16 14:54:35

标签: vb.net postgresql odbc

VB.NET 2019

Postgre 10

Postgre ODBC

DBeaver中的源数据:

https://i86.fastpic.ru/big/2019/0716/b9/_8741664f3e9495646d995a9d96b846b9.png

试图更改SQL状态,更改参数传递:

'Dim command As New Odbc.OdbcCommand("UPDATE public.v8users SET Data = @data WHERE ID = @id", Connection) 'MSSQL syntax
'Dim command As New Odbc.OdbcCommand("UPDATE public.v8users SET data = ?, name = ? WHERE id = ?", Connection)
'Dim command As New Odbc.OdbcCommand("UPDATE public.v8users SET data = ?data WHERE id = ?id", Connection) 'MySQL syntax
'Dim command As New Odbc.OdbcCommand("UPDATE public.v8users SET data = ? WHERE id = decode(encode(?, 'hex'), 'hex')", Connection) 'PostgreSQL syntax

'command.Parameters.Add(New Odbc.OdbcParameter("@id", SQLUser.ID))
'command.Parameters.Add(New Odbc.OdbcParameter("@data", NewBytes))
'command.Parameters.Add(New Odbc.OdbcParameter("id", SqlDbType.Binary)).Value = SQLUser.ID
'command.Parameters.Add(New Odbc.OdbcParameter("data", SqlDbType.Binary)).Value = NewBytes
'command.Parameters.Add(New Odbc.OdbcParameter("name", Odbc.OdbcType.Binary)).Value = NewBytes
Structure SQLUser
   Dim ID As Byte()
   Dim IDStr As String
   Dim Name As String
   Dim Descr As String
   Dim Data As Byte()
   Dim DataStr As String
   Dim PassHash As String
   Dim PassHash2 As String
   Dim AdmRole As String
   Dim KeySize As Integer
   Dim KeyData As Byte()
End Structure

Dim a
Dim Connection = New Odbc.OdbcConnection("Driver={PostgreSQL Unicode};Server=192.168.2.10;Database=TestPurp;Uid=<correct>;Pwd=<correct>;UseServerSidePrepare=1;ReadOnly=0")
Dim command As New Odbc.OdbcCommand("UPDATE public.v8users SET data = ? WHERE id = ?", Connection)
command.Parameters.Clear()
command.Parameters.Add(New Odbc.OdbcParameter("id", Odbc.OdbcType.Binary)).Value = SQLUser.ID
command.Parameters.Add(New Odbc.OdbcParameter("data", Odbc.OdbcType.Binary)).Value = NewBytes
a = command.ExecuteNonQuery()

a = 0,期望a = 1

1 个答案:

答案 0 :(得分:2)

尝试按与Update语句中出现的顺序相同的顺序添加参数。首先添加数据,然后添加ID。

command.Parameters.Add(New Odbc.OdbcParameter("data", Odbc.OdbcType.Binary)).Value = NewBytes
command.Parameters.Add(New Odbc.OdbcParameter("id", Odbc.OdbcType.Binary)).Value = SQLUser.ID

这与OleDb提供程序在Access中的工作方式相同。