Over a million developers have joined DZone.

Storing an Image to a Database in .NET

DZone's Guide to

Storing an Image to a Database in .NET

· ·
Free Resource

Several weeks ago I mentioned that I store the images that the user uploads to the system into the database.

Some of you have expressed an interest in how I do that.  So I plan to cover that today.

For the purposes of this article, I’m going to assume that you’ve already got the image uploaded and scaled and that all that is left is getting it into the database.

First, you need some place to store your image.  For this, you will need a table in your database with a field of type image.

If you use a dataset as your means of accessing the dataset this will give you a field in the DataTable with a type of:

Byte Array (byte[])

So it is a simple matter of taking the byte array that our scaling function returned to us and assigning it to the field in our database that has the photo and then updating our database using the new data.


Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}