Results 1 to 4 of 4

Thread: How to insert/upload any image in database with using Asp.Net program?

  1. #1
    Join Date
    Jul 2013

    How to insert/upload any image in database with using Asp.Net program?

    Hello Friend,
    I want to insert or upload an image in database by asp.net program , so please help and tell me how to do this?

  2. #2
    Join Date
    May 2013
    Surendranagar Gujarat India
    Hi alendonald

    You can try this code that can be used for store image in database
    I will send you two part of code First is used in desogn side and second is used in coding side..

    1.Design Side Code
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="AccessUpload.aspx.cs" Inherits="AccessUpload" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">

    <style type="text/css">
    body{font-family: tahoma;font-size: 80%;}
    .row{clear: both;}
    .label{float: left;text-align: right;width: 150px;padding-right: 5px;}
    <form id="form1" runat="server">
    <div class="row">
    <span class="label"><label for="FirstName">First Name: </label></span>
    <asp:TextBox ID="FirstName" runat="server"></asp:TextBox>
    <div class="row">
    <span class="label"><label for="Surname">Surname: </label></span>
    <asp:TextBox ID="Surname" runat="server"></asp:TextBox>
    <div class="row">
    <span class="label"><label for="Photo">Photo: </label></span>
    <asp:FileUpload ID="PhotoUpload" runat="server" />
    <div class="row">
    <span class="label"><label for="Resume">Resume: </label></span>
    <asp:FileUpload ID="ResumeUpload" runat="server" />
    <div class="row">
    <span class="label">&nbsp;</span>
    <asp:Button ID="Button1" runat="server" Text="Submit" onclick="Button1_Click" />

    2.Code Side
    protected void Button1_Click(object sender, EventArgs e)
    if (PhotoUpload.HasFile && ResumeUpload.HasFile)
    Stream photoStream = PhotoUpload.PostedFile.InputStream;
    int photoLength = PhotoUpload.PostedFile.ContentLength;
    string photoMime = PhotoUpload.PostedFile.ContentType;
    string photoName = Path.GetFileName(PhotoUpload.PostedFile.FileName);
    byte[] photoData = new byte[photoLength - 1];
    photoStream.Read(photoData, 0, photoLength);

    Stream resumeStream = ResumeUpload.PostedFile.InputStream;
    int resumeLength = ResumeUpload.PostedFile.ContentLength;
    string resumeMime = ResumeUpload.PostedFile.ContentType;
    string resumeName = Path.GetFileName(ResumeUpload.PostedFile.FileName);
    byte[] resumeData = new byte[resumeLength - 1];
    resumeStream.Read(resumeData, 0, resumeLength);

    string qry = "INSERT INTO Employees (FirstName, LastName, Photo, PhotoFileName, PhotoMime, Resume,
    ResumeFileName, ResumeMime) VALUES (?,?,?,?,?,?,?,?)";
    string connect = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=|DataDirectory|Northwind.mdb";
    using (OleDbConnection conn = new OleDbConnection(connect))
    OleDbCommand cmd = new OleDbCommand(qry, conn);
    cmd.Parameters.AddWithValue("", FirstName.Text);
    cmd.Parameters.AddWithValue("", Surname.Text);
    cmd.Parameters.AddWithValue("", photoData);
    cmd.Parameters.AddWithValue("", photoName);
    cmd.Parameters.AddWithValue("", photoMime);
    cmd.Parameters.AddWithValue("", resumeData);
    cmd.Parameters.AddWithValue("", resumeName);
    cmd.Parameters.AddWithValue("", resumeMime);

    Gaurav Pandya
    Software Engineer

  3. #3
    Join Date
    Jul 2013
    thanks gaurav. I try this code .

  4. #4
    Join Date
    Nov 2013
    Can I please know what would be the datatype of Photo, PhotoFileName, PhotoMime
    also Resume, ResumeFileName, ResumeMime

    Thanks in advance

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center