locked
Update an image column in database with binary file? RRS feed

  • Question

  • Hi,

    I have a SQL 2008 database that I am select,update and deleting with a Windows user form using Linq from Visual Studio 2008.

    I have 4 tables and I can complete al the steps I need in 3 of the tables. The problem is 1 table where I have 2 columns, File Name and File Data. The data column is an image column and I store text files in it. I use OpenFileDialog for the user to select a file and System.IO.File.ReadAllBytes(_selectedFile); to turn the file in to bytes so I can insert into table. No problems so far.

    The problem is when it comes to updating. On the other tables and the File Name of this table I can search for the required cell and change as they are strings or int's. After submitChanges() the database is changed. The exception I get when trying to update the File Data column is 'Cannot Add An Entitiy That Already Exists'. I know it exists I want to change it!

    The way I see it I have either got to delete to cell first then add or overwrite the cell. Any ideas which way I should go??????

    Regards.

    • Moved by KJian_ Thursday, April 15, 2010 5:28 AM (From:SQL Server Data Access)
    Tuesday, April 13, 2010 1:31 PM

Answers

  • Hi,

    What's the primary key of the table?  Are both FileName and FileData the composite primary keys?  If so, we cannot update the key columns directly, instead please delete the entity and add a new one if we want to update the key columns. 

    If not, please try to set the Update Check (concurrency check) property of the FileData to Never, or it can be some problems when LINQ to SQL performs some concurrency check on the image column with binary data. 


    Best Regards,
    Lingzhi Sun


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Monday, April 19, 2010 3:16 PM