c# - how to delete image which is stored as varbinary format in database -
i have picturebox
image , delete button. image stored in varbinary(max)
format in database. how delete when delete button pressed?
i'm using code save image database:
byte[] data; using (system.io.memorystream stream = new system.io.memorystream()) { conn.open(); image img = picturebox1.image; img.save(stream, system.drawing.imaging.imageformat.jpeg); data = stream.toarray(); cmd.commandtext = "insert images values(@images)"; cmd.parameters.addwithvalue("@images", data); int res = cmd.executenonquery(); messagebox.show("success"); }
i don't see why following wouldn't work.
cmd.commandtext = "delete images id = x";
sending plain sql getting outdated , can down right dangerous when implemented ui improperly, should consider using linq
Comments
Post a Comment