Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple example for storing images / files in SQL Server database ?

Status
Not open for further replies.

StevenK

Programmer
Jan 5, 2001
1,294
GB
Can anyone point me in the direction of a simple (the simpler the better) example of how I can save / read images (or MS Word documents) from a SQL Server database ?
Any suggestions would be appreciated,
Thanks in advance,
Steve
 
Why dont you just create a column in your database which is a string data type, store the file name in that column, then you can reference the file from a central store.

For instance, say you have a images folder under your root directory.

your table could look something like this.
ID - Image Name
1 test1.jpg
2 test2.jpg

you could just pull the information out of the database and build the full path and display the images, or build them into a hyperlink, whatever you want to do. I have never been 100% keen on saving files inside the database, but i am sure people would disagree with me.

e.g. String strFile = "/images/" + yourFilePath;

sorry for the very brief example, hope this gives you a start.

Rob
 
Unless you have a compelling reason to store the 'files' as columns on your database (for example if you want to be able to recover them from the database logs), then I'd go with Modica82's solution.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top