Updating image in VB and SQL Server not working [closed]

There are other things wrong with that code but I’ll concentrate on the two that most directly pertain to your stated issue.

Firstly, you have this within your SQL code:

Img =  '@Spic'

That is wrong. If you want to use the value of a variable in VB, would you wrap the name of the variable in double-quotes? Of course you wouldn’t! That would use a String containing the name of the variable rather than the value of the variable itself. With that in mind, why would you wrap the name of a SQL parameter in single-quotes when the purpose of single-quotes in SQL is specifically to denote a literal string?

Even if you fix that though, it’s still not going to work because of this:

da.UpdateCommand.Parameters.Add(New SqlClient.SqlParameter("@Spic", SqlDbType.Image)).Value = IO.File.ReadAllBytes(ofd.FileName)

da.UpdateCommand = New SqlCommand

You add a parameter to the command object that is currently assigned to the UpdateCommand property, then you immediately discard that command object and replace it with a new one. If you have a bowl of ice cream and you put chocolate sprinkles on it, then toss the ice cream and put a new scopp in the bowl, would you be surprised that there are no chocolate sprinkles on it? Of course not. That’s exactly what you would expect, so why would you think that it would be any different here?

Leave a Comment