Update Command with Parameter....

A

A_PK

Could anyone pls guide me what is wrong with my Update Command

Dim signbyte As Byte()
signbyte = GetByteArray() ' i create this function to return
ByteArray

Try
Dim cmd As New SqlCeCommand
cmd.Connection = myConnection

' Someone give me the following insert statement....this ?
parameter is working,
'but I modify to update statement with @ or ?, both not
working....
'cmd.CommandText = "insert into test (picture) values (?)"

cmd.CommandText = "UPDATE bm00ts0001 SET imgarray = ? WHERE tid
= '" & vartid & "'"
Dim param As SqlCeParameter = cmd.Parameters.Add("imgarray",
SqlDbType.Image)
param.Value = signbyte
myConnection.Open()
cmd.ExecuteNonQuery()
myConnection.Close()

Catch sqex As SqlCeException
MessageBox.Show(sqex.ToString(), "DB operation failed")
Catch er As Exception
MessageBox.Show(er.ToString)
End Try
 
L

Larry Lard

A_PK said:
Could anyone pls guide me what is wrong with my Update Command

Dim signbyte As Byte()
signbyte = GetByteArray() ' i create this function to return
ByteArray

Try
Dim cmd As New SqlCeCommand
cmd.Connection = myConnection

' Someone give me the following insert statement....this ?
parameter is working,
'but I modify to update statement with @ or ?, both not
working....
'cmd.CommandText = "insert into test (picture) values (?)"

cmd.CommandText = "UPDATE bm00ts0001 SET imgarray = ? WHERE tid
= '" & vartid & "'"
Dim param As SqlCeParameter = cmd.Parameters.Add("imgarray",
SqlDbType.Image)
param.Value = signbyte
myConnection.Open()
cmd.ExecuteNonQuery()
myConnection.Close()

Catch sqex As SqlCeException
MessageBox.Show(sqex.ToString(), "DB operation failed")
Catch er As Exception
MessageBox.Show(er.ToString)
End Try


I've always been told that the ? syntax for parameters is an ODBC
thing; when using a direct SQL connection you should use the @name
parameter style. Try the following changes:

Change
cmd.CommandText = "UPDATE bm00ts0001 SET imgarray = ? WHERE tid = '" &
vartid & "'"
To
cmd.CommandText = "UPDATE bm00ts0001 SET imgarray = @imgarray WHERE tid
= '" & vartid & "'"

Change
Dim param As SqlCeParameter = cmd.Parameters.Add("imgarray",
SqlDbType.Image)
To
Dim param As SqlCeParameter = cmd.Parameters.Add("@imgarray",
SqlDbType.Image)

Making these changes meant this code worked for me on a normal (not CE)
SQL Server.
 
A

A_PK

Hi ....I tried the following code u gave me...i am expericing Token Line
Error ...what the problem could be ?
 
L

Larry Lard

What's your exact error message?


A_PK said:
Hi ....I tried the following code u gave me...i am expericing Token Line
Error ...what the problem could be ?
 

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