Home » none » Storing An Image To a Database in .NET

Storing An Image To a Database in .NET


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 someplace 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.

Other places talking about Storing Images from .NET

Store-Retrieve binary data (BLOBs – Audio, Video, Image, Exe, etc … – Tutorial to Store-Retrieve binary data (BLOBs – Audio, Video, Image, Exe, etc.) in database in VB.Net using Array.

FileUpload Save Images in Database in ASP.NET C# VB.NET – NET with C# and VB.NET. Database is having a table named Images with three columns. 1. ID Numeric Primary key with Identity Increment. 2. ImageName Varchar to store Name of Image. 3. Image Image to store image in binary format. …

VB NET Upload image from VB.NET to Amazon S3 Project – Upload image from VB.NET to Amazon S3 freelance project is offered at RentACoder. You will need to have Coder account before you place your bid. If interested, you can get your RentACoder account. In case you already have an account with RentACoder, You can check Projects Details and Apply for … Amazon Product Price Database I am looking for a script that can query amazon at a preset interval (every 4 hours, every day etc thru a cron job) and save prices in a database. …

Like this Article? Subscribe to get every article sent to your email.

Related Post

  • .NET Image Scaling in CSharp.NET Image Scaling in CSharp One feature of .NET that I use regularly is image scaling.  I typically use this on web sites that need image upload capabilities.  I assume the user is going to send me an […]
  • DotNetNuke – Retrieving Host AccessDotNetNuke – Retrieving Host Access One of the most frustrating events that can happen in any system is forgetting your password and not being able to retrieve it.  DotNetNuke has a retrieval system built in, but you […]
  • The easiest way to create a SQL db from CodeThe easiest way to create a SQL db from Code (We'll get back to the series on Reflection next week.) So, I've started experimenting with replacing my TestComplete test scripts with CSharp test scripts.  This shouldn't be too big […]
  • Running Selenium In Parallel With Any .NET Unit Testing ToolRunning Selenium In Parallel With Any .NET Unit Testing Tool Running Selenium in parallel from .NET seems to be a problem because, as of the time of this writing, I’ve yet to find a viable way of running selenium test on multiple browsers using […]
  • What is .NET’s Object.GetHashCode() Used For?What is .NET’s Object.GetHashCode() Used For? Here is a great question from a visitor. “What is the exact use of GetHashCode of an object in .net? Does it have any relation with garbage collection?” Let's answer the second […]

About Dave Bush

Dave Bush is a Full Stack ASP.NET developer. His commitment to quality through test driven development, vast knowledge of C#, HTML, CSS and JavaScript as well as his ability to mentor younger programmers and his passion for Agile/Scrum as defined by the Agile Manifesto and the Scrum Alliance will certainly be an asset to your organization.

  • http://www.wallpaperstop.com Derek Dorian

    TBH i tried to put some binary into DB
    but i was satisfied with the results
    so i am not going to put any binary

  • http://www.geekblogtips.com Nishant Srivastava

    I think file uploading in the database is not a good idea, because it increase the size of our database.

  • Dave


    Yes, it will increase the size of your database. But there are several advantages that storing an image in the database provides that may make it worthwhile. The one that pushed us over the edge is the fact that we were using a server farm with a common database. Putting the images in the database eliminated our need for live sync. Not everyone will want to or need to put their images in a database, but there are times when it does make sense.

    I’m curious what your concerns are about putting it in a database?