Click here to Skip to main content
15,889,216 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i search whole site and articles but i can't find it.
how can i insert files into access database (in desktop application)
please someone help me
Posted

1 solution

All you have to do is read the file into a byte stream
C#
byte[] data = File.ReadAllBytes(path);
then use a parametrized query to insert it to the database. I would recommend you use a OleObject field type as otherwise you may find yourself out of space.
C#
using (OleDbConnection con = new OleDbConnection(strConnect))
    {
    con.Open();
    using (OleDbCommand com = new OleDbCommand("INSERT INTO myTable (myFile) VALUES (@FILE)", con))
        {
        com.Parameters.AddWithValue("@FILE", data);
        com.ExecuteNonQuery();
        }
    }
 
Share this answer
 
Comments
phrozen72 14-Jan-12 15:15pm    
thnx buddy

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