-
Mar 5th, 2011, 02:24 AM
#41
Re: Saving Images in Databases
Originally Posted by moti barski
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.
-
Mar 5th, 2011, 05:57 AM
#42
Banned
Re: Saving Images in Databases
i think it could work with videos not only images
-
Mar 5th, 2011, 06:04 AM
#43
Re: Saving Images in Databases
Originally Posted by moti barski
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.
-
Apr 14th, 2011, 03:11 AM
#44
Junior Member
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?
-
Apr 14th, 2011, 04:45 AM
#45
Re: Saving Images in Databases
Originally Posted by Northy
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.
-
Jan 11th, 2013, 04:15 AM
#46
Fanatic Member
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.
Last edited by ADQUSIT; Jan 11th, 2013 at 04:19 AM.
-
Jan 11th, 2013, 07:33 AM
#47
Re: Saving Images in Databases
Originally Posted by ADQUSIT
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.
-
Jan 15th, 2013, 09:51 AM
#48
Fanatic Member
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.
-
Jan 15th, 2013, 04:28 PM
#49
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
-
Jan 16th, 2013, 11:14 PM
#50
Fanatic Member
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...
-
Jan 17th, 2013, 12:28 AM
#51
Re: Saving Images in Databases
Originally Posted by ADQUSIT
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.
-
Jan 17th, 2013, 05:53 AM
#52
Fanatic Member
Re: Saving Images in Databases
but everything is working all right John, then why i'm having error.
Last edited by ADQUSIT; Jan 17th, 2013 at 07:55 AM.
-
Jan 18th, 2013, 05:19 AM
#53
Fanatic Member
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?
-
Jan 18th, 2013, 05:32 AM
#54
Re: Saving Images in Databases
Originally Posted by ADQUSIT
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.
-
Dec 7th, 2013, 02:25 PM
#55
Junior Member
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...
-
Dec 7th, 2013, 07:46 PM
#56
Re: Saving Images in Databases
Originally Posted by vbfaint
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.
-
Sep 26th, 2014, 07:44 AM
#57
Member
Re: Saving Images in Databases
JM,
I tried to save images into the database using n-tier. But could not manage. How do I pass an image to the object in the Data Layer. Also, how can i retrieve the image using n-tier. Finally, how to make sure it does not run into an error if there is no image or has been removed (while updating the record).
-
Sep 26th, 2014, 01:01 PM
#58
Re: Saving Images in Databases
Firstly, the tiers shouldn't be an issue and are immaterial... you problably mean layers. Layers is logical separation, while tiers is about the physical separation.
At any rate... don't think of it in terms of an image... it's really an array of bytes you're dealing with. The fact that they represent an image is almost immaterial. so using the file, you get a streamreader and read in all the bytes - Syste.IO.File.ReadAllBytes would likely be a quick shortcut... once you have the array, you simply stream it to the parameter in the SQL.
To get it back, you read the binary array from the datatable/parameter... then stream it back into an image that you can then assign to the image/picture box.
And to get around the "error" of no image... don't use it blindly... check the array to see if there is anythign in the first place... if there is, then you proceed.
-tg
-
Sep 26th, 2014, 08:22 PM
#59
Re: Saving Images in Databases
Originally Posted by tomahawk
JM,
I tried to save images into the database using n-tier. But could not manage. How do I pass an image to the object in the Data Layer. Also, how can i retrieve the image using n-tier. Finally, how to make sure it does not run into an error if there is no image or has been removed (while updating the record).
As tg suggests, data is data. You save image data in exactly the same way as you do any other data. In fact, you treat it the same as any other data everywhere. How would you deal with null text or numeric data? That's how you deal with null image data.
If you are having issues then you did it wrong. Maybe you should show us what you did so that we can see what's wrong with it, instead of expecting us to explain it from scratch.
-
Sep 27th, 2014, 11:32 PM
#60
Fanatic Member
Re: Saving Images in Databases
Why we need to convert the image into binary array and then saving it into database. Why we cannot save the image just like we save the value of a textbox or combbox or any other tool?
What is the reason behind saving and retrieve the image in binary fashion?
-
Sep 28th, 2014, 02:12 AM
#61
Re: Saving Images in Databases
Originally Posted by ADQUSIT
Why we need to convert the image into binary array and then saving it into database. Why we cannot save the image just like we save the value of a textbox or combbox or any other tool?
What is the reason behind saving and retrieve the image in binary fashion?
Do you think that a database has a data type that understands what a .NET Image object is? You can save text from a TextBox because text is something universally understood. .NET Images are not universally understood. Databases only have so many data types so you have to make sure the data you save is of one of those data types. Text is universal and there are several text formats: fixed-length, variable-length, single-byte and multi-byte. Numbers are universal and there several numeric types: 8-bit integer, 16-bit integer, 32-bit integer, etc. There's no standard data type for storing Image objects.
SQL Server actually has a data type named `image` but it doesn't actually store Image objects; it stores binary data. It was originally intended to store images but it's been used to store any data in binary from. It's now deprecated and replaced with varbinary.
So, in short, you can't just save a .NET Image object because there is no data type in the database that knows how to handle it.
-
Sep 28th, 2014, 03:31 AM
#62
Fanatic Member
Re: Saving Images in Databases
So are we suppose to use varBinary for storing image, or we can opt any other dataType, suitable for image storing?
-
Sep 28th, 2014, 04:13 AM
#63
Re: Saving Images in Databases
Originally Posted by ADQUSIT
So are we suppose to use varBinary for storing image, or we can opt any other dataType, suitable for image storing?
You use whatever data your particular database has for storing binary data. In SQL Server that's varbinary; in Access it's OLE Object or the like; in Oracle I believe it's BLOB; etc. The data is going to be stored in the database as binary data so, regardless of the database, that's what you need to create in your .NET app to save.
-
Sep 29th, 2014, 06:57 AM
#64
Fanatic Member
Re: Saving Images in Databases
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|