Background
I have often seen the question asking how to upload images to a database in ASP.Net C# but the question ends without a solution. So by considering the preceding requirement I decided to write this article especially focusing on beginners and those who want to learn how to upload Images to a database.
Now before creating the application, let us create a table named ImageTotable or whatever name you wish in a database to store the Uploaded image files in a database table having the following fields (shown in the following image):

In the preceding table, the myphoto column name is used to store the image file and the name is used to store the comment or name which is given to the image.
I hope you have created the same type of table.
Now let us start to create an application to upload image files step-by-step.
- "Start" - "All Programs" - "Microsoft Visual Studio 2010".
- "File" - "New Project" - "C#" - "Empty Project" (to avoid adding a master page).
- Give the project a name, such as ImageUpload or another as you wish and specify the location.
- Then right-click on Solution Explorer - "Add New Item" - Default.aspx page.
- One File upload control, one Button, one textbox, one label
<form id="form1" runat="server">
<div>
<table>
<tr>
<td>
Select Image
</td>
<td>
<asp:FileUpload ID="FileUpload1" runat="server" />
</td>
<tr>
<td>
Select Image
</td>
<td>
<asp:FileUpload ID="FileUpload1" runat="server" />
</td>
Album Name
<td>
<asp:TextBox ID="TextBox1" runat="server" />
</td>
<td>
</td>
</tr>
</table>
<table><tr><td><p><asp:Label ID="Label2" runat="server" Text="label"></asp:Label> </p></td></tr></table>
</div>
</form>

From the preceding view I am using one button to do the upload; one textbox to provide an album name.
Now run the application and click on the save button without selecting an Image file which shows the following error as shown in the following:

Now select the Image file, which shows the following message after being successfully uploaded:

- For detailed code please download the zip file attached above.
- Don't forget to update the Web.config file according to your Server location.

Akagami ShanksPosted Mar 25, 2017, 3:25 AM
What is the purpose of this line: FileUpload1.PostedFile.InputStream.Read(pic, 0, length);
Vithal WadjePosted Apr 12, 2016, 4:28 PM
refer my other articles
Nagesh BadigerPosted Apr 12, 2016, 2:53 PM
k thnks but how to show images form database table ... send me how for this gmail id = [email protected]
Vithal WadjePosted Feb 22, 2016, 9:42 AM
Bibhor kumar ,refer my other articles
Vithal WadjePosted Feb 22, 2016, 9:41 AM
Thanks
Amit Kumar SinghPosted Feb 20, 2016, 7:45 AM
Nice one
tanuj omarPosted May 25, 2015, 2:31 AM
hie frds use this link it will help u https://www.youtube.com/watch?v=1w9BHooz1Yw
Bibhor kumarPosted May 14, 2015, 6:26 AM
how to save image in (sql)database in binary fromate asp.net c#
Vithal WadjePosted Aug 30, 2014, 1:01 AM
thanks sir.its my pleasure
Santhosh KumarPosted Aug 29, 2014, 7:01 AM
thank u
Vithal WadjePosted Aug 28, 2013, 2:41 PM
thanks Rini Sir
RiniPosted Aug 27, 2013, 11:43 PM
Thanx for the soln. it is indeed helpful..
Vithal WadjePosted Mar 25, 2013, 1:17 AM
thanks sir ,for reading my article,this is not a above article error,its you solution file error so create application step by step as i have given
Siddhartha DeyPosted Mar 23, 2013, 3:04 AM
ERROR ...... http://postimg.org/image/4xx3mre2x/
Siddhartha DeyPosted Mar 23, 2013, 2:59 AM
ERROR :-........... Operand type clash: varbinary(max) is incompatible with text ....... Please Help !!
Vithal WadjePosted Mar 15, 2013, 12:08 AM
thanks sir reading my article,soon i will be write article on on it when i got time
Sanket ChougulePosted Mar 14, 2013, 6:30 AM
Thanx for the soln. it is indeed helpful.. now need your help to retrieve the images periodically from the database to show in the web form using timer control
Vithal WadjePosted Mar 12, 2013, 12:18 AM
then you have not any sufficient permission to perform insert ,update,delete operation on database ,check it
Arun kumarPosted Mar 6, 2013, 1:37 AM
I'm nt inserted any primary key on it
Vithal WadjePosted Mar 5, 2013, 5:49 AM
what is your table structure ? if you applied any primary key on above article table structure then remove it
Arun kumarPosted Mar 4, 2013, 10:10 AM
hi sorry sir this occur now"The INSERT permission was denied on the object 'ImageTotable', database 'master', schema 'dbo'."
Vithal WadjePosted Mar 4, 2013, 5:36 AM
thanks arun sir
Arun kumarPosted Mar 4, 2013, 1:41 AM
Working Sir....,Thank you :)
Vithal WadjePosted Feb 28, 2013, 11:22 PM
thanks Talha ,sir for reading my article and can not be understand your question please repeat it
Vithal WadjePosted Feb 28, 2013, 11:21 PM
arun sir ,you have creating many subfolder to store the application thats why you got error just keep solution as F:\Projects\UploadImages and then open
Talha Abdul MuqsitPosted Feb 28, 2013, 10:50 AM
how to fetch it and bind with image
Arun kumarPosted Feb 28, 2013, 5:18 AM
rectify that error sir"Error 1 Could not load type 'UploadImages.Default'. F:\Projects\UploadImages\UploadImages\UploadImages\Default.aspx 1 "
Vithal WadjePosted Feb 10, 2013, 10:05 PM
Rahul check your database table column filed datatype in whhich you have stored image or create a table as i have created above
Rahul SoniPosted Feb 7, 2013, 4:44 AM
Operand type clash: nvarchar is incompatible with image this error is generard
Rahul SoniPosted Feb 7, 2013, 4:44 AM
Operand type clash: nvarchar is incompatible with image this error is generard
Vithal WadjePosted Jan 29, 2013, 12:33 AM
for this you can refer my other articles
Ripon NathPosted Jan 28, 2013, 4:22 PM
can you plz tell how to retrive image form a database in an ASP.NET Application......am trying very hard but not getting any result.....RIPON...
Ripon NathPosted Jan 28, 2013, 4:22 PM
can you plz tell how to retrive image form a database in an ASP.NET Application......am trying very hard but not getting any result.....RIPON...
Vithal WadjePosted Jan 4, 2013, 4:53 AM
its depends upon your requirement,but is beeter way to store the uploaded images in database instaed of application folder ,according to my experience if we store the images into application folder ,it may result to slow an application.. whats about your opinion ?
Rohatash KumareditedPosted Jan 4, 2013, 3:41 AMEdited Jan 4, 2013, 3:44 AM
Nice article Vithal. How we can upload image to application folder. uploading a image to application folder or database Which is better way to do it. vithal