Re: Saving Images in Databases
Quote:
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.
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?
Re: Saving Images in Databases
Quote:
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.
Re: Saving Images in Databases