Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to save images in oledb database and retrive
Posted
Comments
Patel Shailendra 7-Dec-12 7:23am    
what you use for storing data. sql server, access ..or what..?

Find my answer from following link

--SJ
 
Share this answer
 
v2
http://www.aspdotnet-suresh.com/2011/01/how-to-insert-images-into-database-and.html

check this link
 
Share this answer
 
v2
Hi,



-- First Create the database
Create Database Test_DB;
-- After execution of First command execute the following query
use Test_DB;
CREATE TABLE [dbo].[file_db](
    [file_name] [varchar](50) NOT NULL,
    [file_Content] [varbinary](max) NULL,
    )


// It will help you to insert the file into the db
void insertFile()
        {
            FileStream fs = new FileStream(@"c:\file\input.txt", FileMode.Open, FileAccess.Read);
            int length = Convert.ToInt32(fs.Length);
            byte[] data = new byte[length];
            fs.Read(data, 0, length);
            fs.Close();
            string insert = "insert into file_db values('input.txt',@file_content)";
            DataSet ds = new DataSet();
            SqlConnection conn = new SqlConnection(con);
            conn.Open();
            SqlCommand cmd = new SqlCommand(insert, conn);
            cmd.Parameters.Add(new SqlParameter("@file_content", (object)data));
            cmd.ExecuteNonQuery();
            conn.Close();
        }
// It will help you to read the inserted file content from db
 void ReadFile()
        {
            SqlConnection conn = new SqlConnection(con);
            string qry = "select file_content from file_db where file_name='input.txt'";
            SqlCommand cmd = new SqlCommand(qry, conn);
            conn.Open();
            SqlDataReader dr = cmd.ExecuteReader();
            dr.Read();
            byte[] output = (byte[])dr[0];
            dr.Close();
            conn.Close();
            FileStream fs = new FileStream(@"C:\file\output.txt", FileMode.Create, FileAccess.Write);
            fs.Write(output, 0, output.Length);
            fs.Close();
        }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900