Forum     

Go Back   Digit Technology Discussion Forum > Software > Programming
Register FAQ Calendar Mark Forums Read

Programming The destination for developers - C, C++, Java, Python and the lot


Reply
 
LinkBack Thread Tools Display Modes
Old 08-05-2011, 07:11 PM   #1 (permalink)
The Thunderer
 
bhutanesedude's Avatar
 
Join Date: Jun 2007
Location: Thimphu, Bhutan
Posts: 151
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.
bhutanesedude is offline   Reply With Quote
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 08-05-2011, 10:09 PM   #2 (permalink)
XLr8
 
arpanmukherjee1's Avatar
 
Join Date: Sep 2008
Posts: 637
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
__________________
Quote:
There are more things in heaven and earth, Horatio,
Than are dreamt of in your philosophy.
arpanmukherjee1 is offline   Reply With Quote
Old 09-05-2011, 01:21 AM   #3 (permalink)
Simply a DIGITian
 
krishnandu.sarkar's Avatar
 
Join Date: Nov 2007
Location: Kolkata
Posts: 2,942
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
krishnandu.sarkar is online now   Reply With Quote
Old 12-05-2011, 02:45 PM   #4 (permalink)
The Thunderer
 
bhutanesedude's Avatar
 
Join Date: Jun 2007
Location: Thimphu, Bhutan
Posts: 151
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.
bhutanesedude is offline   Reply With Quote
Old 12-05-2011, 09:27 PM   #5 (permalink)
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...
amirajdhawan is offline   Reply With Quote
Old 27-05-2011, 07:07 PM   #6 (permalink)
The Thunderer
 
bhutanesedude's Avatar
 
Join Date: Jun 2007
Location: Thimphu, Bhutan
Posts: 151
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.
bhutanesedude is offline   Reply With Quote
Old 27-05-2011, 08:01 PM   #7 (permalink)
Simply a DIGITian
 
krishnandu.sarkar's Avatar
 
Join Date: Nov 2007
Location: Kolkata
Posts: 2,942
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
krishnandu.sarkar is online now   Reply With Quote
Old 28-05-2011, 12:27 AM   #8 (permalink)
XLr8
 
arpanmukherjee1's Avatar
 
Join Date: Sep 2008
Posts: 637
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??
__________________
Quote:
There are more things in heaven and earth, Horatio,
Than are dreamt of in your philosophy.

Last edited by arpanmukherjee1; 28-05-2011 at 12:44 AM.
arpanmukherjee1 is offline   Reply With Quote
Old 30-05-2011, 10:31 PM   #9 (permalink)
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!
amirajdhawan is offline   Reply With Quote
Old 08-06-2011, 03:40 AM   #10 (permalink)
The Thunderer
 
bhutanesedude's Avatar
 
Join Date: Jun 2007
Location: Thimphu, Bhutan
Posts: 151
Default Re: How to store Images in database table using VB.NET

Thank you to all...I understood....
bhutanesedude is offline   Reply With Quote
Old 08-06-2011, 10:21 AM   #11 (permalink)
Fullbring
 
Zangetsu's Avatar
 
Join Date: Jan 2008
Location: Soul Society
Posts: 5,523
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.
__________________
I'm the One you've been Waiting for...
Zangetsu is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


 
Latest Threads
- by Charan
- by Sarath
- by clmlbx

Advertisement




All times are GMT +5.5. The time now is 12:27 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2