Is it possible to update a binary field in SQL Server?
I know how to insert a new row into a table with a binary column. But is there a way to update the binary column after adding this row? So far, an exhaustive Google search has shown nothing.
My solution so far
- Get the current line that I want to update
- delete the line i want to update
- Create a new line with information from the line I want to update plus a new binary
It's just not very elegant and I was hoping I could do the same with the update instructions.
Here is the updated code that I am using now for reference
Dim objCommand As New SqlCommand("UPDATE " & Tablename & " SET " _
& column & " = Data WHERE " & criteria)
objCommand.Parameters.Add("@Data", SqlDbType.Image)
objCommand.Parameters("@Data").Value = BinaryData
a source to share
INSERT BINARY / BYTES
INSERT INTO table_name
(field_name)
VALUES
(4|8|16|32)
UPDATE BINARS / BYTE
UPDATE table_name
SET field_name=field_name|8|16|32
WHERE field_name_filter=@this_value
NOTE. ... When the byte flag is set, you cannot update it to remove it. So you cannot use the UPDATE example to remove a byte that was set to 4 and then want to change it to 8, it just adds 8, so now you have 4 | 8. Also, the reverse byte placement is harder than the seam, it's not just UPDATE -4 | 8.
It's easier to query the results, delete the record and insert it as a new record with old data (from the first query), and reformat the correct byte flags.
At least this is my limited experience with this
a source to share