none
Problem saving picture in the mdf database Visual Studio 2008 RRS feed

  • Question

  • Hi everyone,

      Can any one give me a easiest solution for saving pic in the mdf database so as to enable me operating my project in any comp once it is individually installed.  I have made a project of my org with different fields in the mdf database. In my own comp I have no problem to scroll all the fields and see the pic of individual. But, when I install this prog in other comp I can scroll all the fields but I can not see the pic because the pic forlder in the hard disk of previous comp. So I thought if it is possible to attach all the pic field in the databse it will be convenient to operate this prog in any comp if it is individually installed. Your suggestion of easiest solution will be highly appriciated. Be informed that I am using VB 2008 and the data bse is mdf.
    Sunday, October 11, 2009 5:09 AM

Answers

  • Hi wasekMajlis,

    The easiest solution for saving a picture is to use the T-SQL statement in the SQL Server Management Studio.

    For example, suppose that you use the following statement to create a table:

      CREATE TABLE Test
      (
      PicID int IDENTITY(1,1),
      PicName varChar(50),
      PicData varBinary(MAX)
      );
    And then you can use the following SQL statement to insert an image from your hard disk:

          INSERT INTO Test
          (PicName, PicData)
          SELECT 'First test file',
          BulkColumn FROM OPENROWSET(
          Bulk 'C:\test.jpg', SINGLE_BLOB) AS BLOB

    I notice that you emphasized that you are not using the SQL Server database but the database as an MDF file. Well, for you case, you can import the MDF file with the SQL Server Management Studio and then copy the mdf file to other directories you like after the 'insert-image' operation.

    Best regards,
    Charlie Lee

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    • Marked as answer by Zhipeng Lee Friday, October 16, 2009 8:55 AM
    Thursday, October 15, 2009 3:41 AM
  • You have to convert image first to byte array.
    Hope this article helps.
    http://www.shabdar.org/store-save-images-in-sql-server.html
    • Marked as answer by WasekMajlis Sunday, October 11, 2009 2:20 PM
    • Unmarked as answer by WasekMajlis Sunday, October 11, 2009 2:21 PM
    • Proposed as answer by Tamer Oz Tuesday, October 13, 2009 7:42 PM
    • Marked as answer by Yichun_Feng Friday, October 16, 2009 8:57 AM
    Sunday, October 11, 2009 7:25 AM

All replies

  • You have to convert image first to byte array.
    Hope this article helps.
    http://www.shabdar.org/store-save-images-in-sql-server.html
    • Marked as answer by WasekMajlis Sunday, October 11, 2009 2:20 PM
    • Unmarked as answer by WasekMajlis Sunday, October 11, 2009 2:21 PM
    • Proposed as answer by Tamer Oz Tuesday, October 13, 2009 7:42 PM
    • Marked as answer by Yichun_Feng Friday, October 16, 2009 8:57 AM
    Sunday, October 11, 2009 7:25 AM
  • Hi Tamer OZ,

     Thanks for yr link. it does not address what I actually looking for. I am not using SQL Server database using C#. I am using servised based databse as mdf using visual studio 2008.
    can u plz help if u have any clue.
    Sunday, October 11, 2009 2:24 PM
  • There is no difference between saving to an mdf(SQL Express) and SQL Server.

    All datatypes are same.

    Just try the code i posted and let me know if any errors.
    Sunday, October 11, 2009 2:30 PM
  • Hi wasekMajlis,

    The easiest solution for saving a picture is to use the T-SQL statement in the SQL Server Management Studio.

    For example, suppose that you use the following statement to create a table:

      CREATE TABLE Test
      (
      PicID int IDENTITY(1,1),
      PicName varChar(50),
      PicData varBinary(MAX)
      );
    And then you can use the following SQL statement to insert an image from your hard disk:

          INSERT INTO Test
          (PicName, PicData)
          SELECT 'First test file',
          BulkColumn FROM OPENROWSET(
          Bulk 'C:\test.jpg', SINGLE_BLOB) AS BLOB

    I notice that you emphasized that you are not using the SQL Server database but the database as an MDF file. Well, for you case, you can import the MDF file with the SQL Server Management Studio and then copy the mdf file to other directories you like after the 'insert-image' operation.

    Best regards,
    Charlie Lee

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    • Marked as answer by Zhipeng Lee Friday, October 16, 2009 8:55 AM
    Thursday, October 15, 2009 3:41 AM