Results 1 to 11 of 11
  1. #1
    The Thunderer bhutanesedude's Avatar
    Join Date
    Jun 2007
    Location
    Thimphu, Bhutan
    Posts
    170

    Post How to store Images in database table using VB.NET

    Guys, I would like the experts to share us some insights about how to insert (upload) and retrive, along with deleting image, using a Windows Application.

    Possibly, I would also like to know the limit of image to be uploaded such as through size (LxB) or through size in KB or MB etc.

  2. #2
    XLr8 arpanmukherjee1's Avatar
    Join Date
    Sep 2008
    Posts
    626

    Default Re: How to store Images in database table using VB.NET

    which DB ?

    for SQL use 'image' data type
    max size that can be uploaded using 'image' is 1.9GB

    also use varbinary() with max size 7.8 MB if it fulfills the requirement
    There are more things in heaven and earth, Horatio,
    Than are dreamt of in your philosophy.

  3. #3
    Simply a DIGITian krishnandu.sarkar's Avatar
    Join Date
    Nov 2007
    Location
    Kolkata
    Posts
    3,493

    Default Re: How to store Images in database table using VB.NET

    Or you can just store the path of the image in some field and retrieve it later while showing.
    • Read The Forum RULES First.
    • Before PM'ing Or Asking Any Questions To Any Mod Read The FAQ's
    • Before Starting A New Thread Read The STICKY THREADS First
    • Before Participating In Bazaar Section Read The BAZAAR RULES

  4. #4
    The Thunderer bhutanesedude's Avatar
    Join Date
    Jun 2007
    Location
    Thimphu, Bhutan
    Posts
    170

    Red face Re: How to store Images in database table using VB.NET

    Guys thank you for the response but what I really mean is, I am trying to develop a Stand-Alone Mini SOftware, in which a student details is saved in DB. Now I want it to be able to insert it's photo (Passport Size Photo) and retrive it whenever required. Well, I know that in DB Table the field type should be "image" but I want to know what should I write behind the coding of "upload" button to save that BROWSED image into the particular database. For instance I shall be using MDF database in VB.NET 2008.

    Acctually I am a new bie in this and I tried googling it too but could not understand. Please help me.

  5. #5
    Right Off the Assembly Line
    Join Date
    Jul 2009
    Posts
    23

    Default Re: How to store Images in database table using VB.NET

    I think the second post by arpan is the bettr optn...using normal file classes of VB store the photos with the primary key...like for ur case store the photos in a folder say photos with d name of student id whch is ur primary key in the db...by this you dont need any new attribute in db...wen u r retreiving the details of a student u would obviously have to enter the student id...get the details of the student from the db n the photo yourself using the image class of vb giving the source "foldername/studentid.jpg" or what evr format you wnt to store....i have used the same thing and it works faster then using d db to store the images using image data type...
    And still if you want to use db den to insert an image you simply do the same thing as you insert other values...just give the source path of the image you putting in the db...

  6. #6
    The Thunderer bhutanesedude's Avatar
    Join Date
    Jun 2007
    Location
    Thimphu, Bhutan
    Posts
    170

    Default Re: How to store Images in database table using VB.NET

    Thank you so much for the wonderful comments and indeed i tried the copying of file address instead of uplaoding the image, but now one problem I cam across, is like, if the user deletes the file in the original location, then theres the error...so now I would like to know if theres anyway to copy that particular Image(which ever is going to be uploaded) into one of the folder which will be in system file of the software......And if possible, pplease do let me know the ways as well the coding needed too....

    Thank you to all once again.

  7. #7
    Simply a DIGITian krishnandu.sarkar's Avatar
    Join Date
    Nov 2007
    Location
    Kolkata
    Posts
    3,493

    Default Re: How to store Images in database table using VB.NET

    Well, he said, copy the pic in to a directory say Images/ under your application folder. Now whenever you need to retrieve it, get it from the %APP%/Images/.

    So if user deletes the original file, you have it's copy.
    • Read The Forum RULES First.
    • Before PM'ing Or Asking Any Questions To Any Mod Read The FAQ's
    • Before Starting A New Thread Read The STICKY THREADS First
    • Before Participating In Bazaar Section Read The BAZAAR RULES

  8. #8
    XLr8 arpanmukherjee1's Avatar
    Join Date
    Sep 2008
    Posts
    626

    Default Re: How to store Images in database table using VB.NET

    here the %APP% = Application.StartupPath

    if you have doubt in ADO.net refer to this
    SQL syntax for inserting values

    i recommend you read and understand the steps involved in running sql query :
    1. connection string is defined. eg the DB is SQL 2008 then the string will be something like this
    2. SQL command is generated
    3. create SqlConnection object.
    4. create SqlCommand object
    5. open the connection
    6. execute command object by any of 4 methods (depends on sql query i.e UPDATE, INSERT, or DELETE = ExecuteNonQuery otherwise ExecuteReader/ExecuteScalar)
    7. dispose command object
    8. dispose connection object

    any more questions??
    Last edited by arpanmukherjee1; 28-05-2011 at 12:44 AM.
    There are more things in heaven and earth, Horatio,
    Than are dreamt of in your philosophy.

  9. #9
    Right Off the Assembly Line
    Join Date
    Jul 2009
    Posts
    23

    Default Re: How to store Images in database table using VB.NET

    In the database you don't have to give the location of the original folder from where the user is uploading the image...
    1. Ask the user for the image path.
    2. Copy the image from the path given by user, to a folder in your application say /images. This can be done using File.copy() method available in system.io(you might have to cross check) or use File.move() if you want to move image from users path to your apps path.
    3. In the database enter the location of the image as per your application paths image and not of the original path given by the user.

    P.S. for copying or moving files in the folder say program files/ ur app/ images, you would have to give your application administrative rights. For that add a manifest for your application and change a value to administrator....this is very simple just google it out( I cant remem properly about)


    Hope this helps..cheers!

  10. #10
    The Thunderer bhutanesedude's Avatar
    Join Date
    Jun 2007
    Location
    Thimphu, Bhutan
    Posts
    170

    Default Re: How to store Images in database table using VB.NET

    Thank you to all...I understood....

  11. #11
    122.26.11.85 Zangetsu's Avatar
    Join Date
    Jan 2008
    Location
    Soul Society
    Posts
    6,692

    Default Re: How to store Images in database table using VB.NET

    Quote Originally Posted by bhutanesedude View Post
    GNow I want it to be able to insert it's photo (Passport Size Photo) and retrive it whenever required. Well, I know that in DB Table the field type should be "image" but I want to know what should I write behind the coding of "upload" button to save that BROWSED image into the particular database.
    its very simple...

    declare a variable array of type byte.

    e.g:
    byte[] imageSize = new byte[FileUpload1.PostedFile.ContentLength];
    HttpPostedFile uploadedImage = FileUpload1.PostedFile;
    uploadedImage.InputStream.Read(imageSize, 0, (int)FileUpload1.PostedFile.ContentLength);

    then use dynamic sql query "insert into..." or stored procedure....pass the
    parameter uploadedImage to the Command Text

    thats it.
    HTC One V | Nokia 5233 | Nikon D3100 | Apple Ipod Touch 4G | Sound Magic PL21 | Sound Magic ES18

Similar Threads

  1. How to make a table?
    By ArjunKiller in forum Chit-Chat
    Replies: 7
    Last Post: 24-05-2012, 01:16 PM
  2. partition table
    By amrutansu garanaik in forum Software Q&A
    Replies: 5
    Last Post: 10-03-2012, 05:09 AM
  3. Help: Store video/image files in database
    By speedyguy in forum Programming
    Replies: 5
    Last Post: 01-07-2011, 10:35 AM
  4. which computer table to buy ?
    By sagargv in forum QnA (read only)
    Replies: 6
    Last Post: 15-06-2008, 12:59 PM
  5. No Images/Cached Images for IE???
    By ╬Switch╬ in forum QnA (read only)
    Replies: 1
    Last Post: 12-03-2008, 02:36 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Close