VB.net - UPDATE query with binary data

S

SiD`

Hi, I am trying to update a field in a record of a Access Database
(whose structure I can not modify).

I got this error (translated from italian): "Data types do not match
in the expression" = "Tipi di dati non corrispondenti nell'espressione
criterio."

The code is the following: (myField is a binary field as on Access
2007)

'determine new value
Dim newValue() As Byte = ... (valid data)

'write new attributes
Dim conn As OleDbConnection = myObj.getConnection
Dim cmd As OleDbCommand = conn.CreateCommand
cmd.CommandType = CommandType.Text

cmd.CommandText = "UPDATE myTable SET myField =
@newValue WHERE fId = @id"

Dim par As New OleDbParameter("@newValue",
OleDbType.Binary)
par.Value = newValue
cmd.Parameters.Add(par)

cmd.Parameters.Add(New OleDbParameter("@id", ID))

conn.Open()
cmd.ExecuteNonQuery()

conn.Close()

Does anybody know the problem about it?

Thanks,
Sid.
 
M

Michel Walsh

While I neither use VB.Net, neither this approach in C#, but it seems you
may use a Large Binary Object data type rather than a bit type. Maybe
changing

OleDbType.Binary

to

GetType(Byte)

would perform better?


Vanderghast, Access MVP
 
S

SiD`

Thanks for the reply.
I tried modifying the code, but the error remains the same.

What kind of approach would you use in C#?

Thanks again,
SiD.
 
M

Michel Walsh

I use an MSDataSetGenerator in general, and, on very few occasions, I
compose the SQL text of the command itself.


Vanderghast, Access MVP
 
S

SiD`

Ok, It seems the I resolved it: the problem was about the order in
which the parameters are added.
In access the parameter name does not be evaluated but the order.
Obviously the query is evaluated first in the WHERE clause, so the ID
must be provided first.
 
M

Michel Walsh

I knew that was a problem with ADO, but I was on the impression it was
'corrected' in ADO.Net.



Vanderghast, Access MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top