Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
how to save images in oledb database and retrive
Posted 6-Dec-12 23:38pm
Deepkak553
Comments
ShailendraPatel at 7-Dec-12 7:23am
   
what you use for storing data. sql server, access ..or what..?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Find my answer from following link
 
--SJ
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

http://www.aspdotnet-suresh.com/2011/01/how-to-insert-images-into-database-and.html
 
check this link
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

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();
        }
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 310
1 Sergey Alexandrovich Kryukov 166
2 PhilLenoir 164
3 Richard MacCutchan 160
4 Sharmanuj 146
0 Sergey Alexandrovich Kryukov 6,081
1 OriginalGriff 5,115
2 CPallini 2,473
3 Richard MacCutchan 1,597
4 Abhinav S 1,505


Advertise | Privacy | Mobile
Web02 | 2.8.140814.1 | Last Updated 7 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100