Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6176209
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:03:38+00:00 2026-05-24T00:03:38+00:00

How can I add one or more files that are saved in a MS

  • 0

How can I add one or more files that are saved in a MS SQL database to an email? I already know how to attach files saved in a directory or from a fileUpload control.

My datable fields are as such:

col1: Email_ID – int

col2: file_name – varchar

col3: file_content – image

So my SQL select statement is prety simple:

Select file_name, file_content from Attachments where Email_ID = 333

I just can’t figure how to attach them to my emails afterwards.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T00:03:38+00:00Added an answer on May 24, 2026 at 12:03 am
      SqlCommand cmdSelect=new SqlCommand("Select file_name, file_content " + 
                  " from Attachments where Email_ID=@ID",this.sqlConnection1);
            cmdSelect.Parameters.Add("@ID",SqlDbType.Int,4);
            cmdSelect.Parameters["@ID"].Value=333;
    
    DataTable dt = new DataTable();
            this.sqlConnection1.Open();
            SqlDataAdapter sda = new SqlDataAdapter();
                sda.SelectCommand = cmdSelect;
                sda.Fill(dt);
         if(dt.Rows.Count > 0)
    {
            byte[] barrImg=(byte[])dt.Rows[0]["file_content"];
            string strfn= "Your File Directory Path" + Convert.ToString(dt.Rows[0]["file_name"]);
            FileStream fs=new FileStream(strfn, 
                              FileMode.CreateNew, FileAccess.Write);
            fs.Write(barrImg,0,barrImg.Length);
            fs.Flush();
            fs.Close();
       //now you can attache you file to email here your file is generate at path stored in "strfn" variable
    }
    

    References : http://www.codeproject.com/KB/database/ImageSaveInDataBase.aspx

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can one add two long values in Java so that if the result
I know one can add event listener for window.error. However when working with Iframes,
How can I add a drop shadow effect to a website that has one
I know that I can add a HintPath to an external DLLs to help
I would like to create a list of records. I can add one record
Edited to Add * I haven't found a solution for this one yet, can
I know I can add a icon to the Resources.resx file of a project
How can I get tar/cp to copy only files that dont end in .jar
I got this simple jquery plugin to upload files. i can add multiple files,
  I have a file copy program that takes from one file and pastes in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.