Saving Images in Databases - Page 2-VBForums
Page 2 of 2 FirstFirst 12
Results 41 to 56 of 56

Thread: Saving Images in Databases

  1. #41

    Thread Starter
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    87,325

    Re: Saving Images in Databases

    Quote Originally Posted by moti barski View Post
    jmcilhinney what about the delete and update of the pictures
    The image is just data in the database like any other. You treat it exactly like any other data. If you have text or numbers in the database and you want to remove or replace them then you set that column of the row to either NULL or a new value. Exactly the same goes here. For instance, if you wanted to edit an image, you would query the database to get the current image, edit in your app, then save the new data, just as you would if you wanted to edit text.

    2007-2014

    Why is my data not saved to my database? | MSDN Data Walkthroughs
    MSDN "How Do I?" Videos: VB | C#
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts) | WP8 Turnstile Feather Transition with Pivot Control
    Beginner Tutorials: VB | C# | SQL

  2. #42
    Fanatic Member
    Join Date
    Mar 2009
    Posts
    760

    Re: Saving Images in Databases

    i think it could work with videos not only images
    time to amp up the beef

  3. #43

    Thread Starter
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    87,325

    Re: Saving Images in Databases

    Quote Originally Posted by moti barski View Post
    i think it could work with videos not only images
    Data is data. It would work with anything that needs to be stored in binary form. I chose to write this thread about images because it was a such a common request.

    2007-2014

    Why is my data not saved to my database? | MSDN Data Walkthroughs
    MSDN "How Do I?" Videos: VB | C#
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts) | WP8 Turnstile Feather Transition with Pivot Control
    Beginner Tutorials: VB | C# | SQL

  4. #44
    Junior Member
    Join Date
    Apr 2011
    Location
    QLD, Australia
    Posts
    22

    Re: Saving Images in Databases

    very nice code, works great with my project.

    One thing i was wondering though, if a photo has other data stored against it, like x and y coords etc. Is this able to be extracted to a variable at the point of uploading the image?

  5. #45

    Thread Starter
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    87,325

    Re: Saving Images in Databases

    Quote Originally Posted by Northy View Post
    very nice code, works great with my project.

    One thing i was wondering though, if a photo has other data stored against it, like x and y coords etc. Is this able to be extracted to a variable at the point of uploading the image?
    Certainly. Exactly how depends on the data format. That is beyond the scope of this thread though. You should start a new thread in the appropriate forum for more info.

    2007-2014

    Why is my data not saved to my database? | MSDN Data Walkthroughs
    MSDN "How Do I?" Videos: VB | C#
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts) | WP8 Turnstile Feather Transition with Pivot Control
    Beginner Tutorials: VB | C# | SQL

  6. #46
    Fanatic Member
    Join Date
    Nov 2010
    Posts
    909

    Re: Saving Images in Databases

    Hi John. I'm here first time to view this spectacular post, you provided. I'm not picking it completely, so starting from first please tell me that in the line No. 2, of vb.net code block, what is update mean there? Will I not insert the image by using insert query? If not, then how i will insert the entire form data, including image.

  7. #47

    Thread Starter
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    87,325

    Re: Saving Images in Databases

    Quote Originally Posted by ADQUSIT View Post
    Hi John. I'm here first time to view this spectacular post, you provided. I'm not picking it completely, so starting from first please tell me that in the line No. 2, of vb.net code block, what is update mean there? Will I not insert the image by using insert query? If not, then how i will insert the entire form data, including image.
    The actual database is just ADO.NET, the same as any other ADO.NET. You retrieve, insert and update image data in exactly the same way as you do any other data. This thread is purely about the trick of using a MemoryStream to convert between an Image object and a Byte array. As far as ADO.NET is concerned, the Byte array is exactly the same as a String or Integer or any other data you move between your app and a database. Don;t try to make this into something difficult when it's not.

    2007-2014

    Why is my data not saved to my database? | MSDN Data Walkthroughs
    MSDN "How Do I?" Videos: VB | C#
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts) | WP8 Turnstile Feather Transition with Pivot Control
    Beginner Tutorials: VB | C# | SQL

  8. #48
    Fanatic Member
    Join Date
    Nov 2010
    Posts
    909

    Re: Saving Images in Databases

    Its all right, that its an only a trick of using a memoryStream..... right.

    Ok, but please tell me how do I insert image in database. If one is unknown about inserting image (for the first time) so he will definitely face so many problems, so how to solve them? Please John, You are the most senior person, for everyone in the forum. If you will not put the light in the dark roads of newbies, then how they will be professional. Pleasseeee, assist me guide me or refer to me some proper place, from where I can learn it from very beginning that how to insert image, in database, using vb.net.....

    I have very very solid hope from you, being so senior in this forum.

  9. #49
    PowerPoster
    Join Date
    May 2002
    Posts
    24,761

    Re: Saving Images in Databases

    I'm not sure what more you need...
    1) create a sql statement that updates the table, setting the field with binary data... be sure to use a parameter...
    2) add the parameter to the parameters collection
    3) Put the bits of the image into the parameter.... an array of bytes works, as does a stream... could be a memory stream... a file stream... doesn't matter... as long as it's a stream....
    4) execute it...

    you're over thinking it... it's not rocket science... you want an example, post #1 has a very good example... your other post on the same thing, dday provided a LINE by LINE analysis of how it works...


    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  10. #50
    Fanatic Member
    Join Date
    Nov 2010
    Posts
    909

    Re: Saving Images in Databases

    I've done all what you wanted me to do, but its now giving me an exception of file not found, in my another post...

  11. #51

    Thread Starter
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    87,325

    Re: Saving Images in Databases

    Quote Originally Posted by ADQUSIT View Post
    I've done all what you wanted me to do, but its now giving me an exception of file not found, in my another post...
    It should be fairly obvious what the problem is if the exception tells you that it can't find the file you specified.

    2007-2014

    Why is my data not saved to my database? | MSDN Data Walkthroughs
    MSDN "How Do I?" Videos: VB | C#
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts) | WP8 Turnstile Feather Transition with Pivot Control
    Beginner Tutorials: VB | C# | SQL

  12. #52
    Fanatic Member
    Join Date
    Nov 2010
    Posts
    909

    Re: Saving Images in Databases

    but everything is working all right John, then why i'm having error.

  13. #53
    Fanatic Member
    Join Date
    Nov 2010
    Posts
    909

    Re: Saving Images in Databases

    Hmmmmm. Hi John, I have performed all the things correctly, by the great help of all my respected members. I followed your code as well in my problem and i finally got achievement. But there is a little problem, your code, makes me able to select the same image, while i want different image everytime. the path which i have given in code:

    Using picture As Image = Image.FromFile("C:\Documents and Settings\ADQUSIT\Desktop\dwn.jpg")
    It does not select any other picture? please assist me that how to select different pictures?

  14. #54

    Thread Starter
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    87,325

    Re: Saving Images in Databases

    Quote Originally Posted by ADQUSIT View Post
    Hmmmmm. Hi John, I have performed all the things correctly, by the great help of all my respected members. I followed your code as well in my problem and i finally got achievement. But there is a little problem, your code, makes me able to select the same image, while i want different image everytime. the path which i have given in code:



    It does not select any other picture? please assist me that how to select different pictures?
    That has nothing to do with the topic of this thread.

    2007-2014

    Why is my data not saved to my database? | MSDN Data Walkthroughs
    MSDN "How Do I?" Videos: VB | C#
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts) | WP8 Turnstile Feather Transition with Pivot Control
    Beginner Tutorials: VB | C# | SQL

  15. #55
    Junior Member
    Join Date
    Mar 2013
    Posts
    26

    Re: Saving Images in Databases

    How to do this?? :

    I have a picturebox and a mysql database table named picture where cells > id, picture
    So now i only input Image.Location into my db table where id = something

    and then when i select id from a listview picturebox will show the image from mysql database field where i put image location..
    Please help me on this...

  16. #56

    Thread Starter
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    87,325

    Re: Saving Images in Databases

    Quote Originally Posted by vbfaint View Post
    How to do this?? :

    I have a picturebox and a mysql database table named picture where cells > id, picture
    So now i only input Image.Location into my db table where id = something

    and then when i select id from a listview picturebox will show the image from mysql database field where i put image location..
    Please help me on this...
    So, you're saying that you want to save the path of an image file to the database? If so then this thread is not the place for it because this thread is specifically about saving images in databases, not text. A file path is just text, so you save it and retrieve it in exactly the same way as any other text. At the other end, loading an image into a PictureBox from a file path is exactly the same regardless of where the file path comes from. If you've done any research on this at all then you already have all the information you need.

    2007-2014

    Why is my data not saved to my database? | MSDN Data Walkthroughs
    MSDN "How Do I?" Videos: VB | C#
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts) | WP8 Turnstile Feather Transition with Pivot Control
    Beginner Tutorials: VB | C# | SQL

Page 2 of 2 FirstFirst 12

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.