Save an Image to SQL Server
Learn how to store an image file in a SQL Server 2000 table using the image data type.
The text of this article is not in this database — only its details are. The old site it was published on is gone, but the Internet Archive kept a copy: Save an Image to SQL Server


Awadhendra TiwariPosted Aug 22, 2011, 6:57 AM EDT
Save Image in SQL Server: http://www.mindstick.com/Articles/982a3316-c8a6-4b81-82ef-c064f27118d9/?Store%20image%20in%20SQL%20Server%20database Save Image in SQL Server by using C# http://www.mindstick.com/Blog/184/Save%20image%20in%20SqlServer%20using%20C
Uyya AzzaPosted Dec 26, 2010, 4:39 PM EST
Thanks yooo 4 article... :)
Golam TaherPosted Aug 7, 2010, 9:11 AM EDT
Very Useful
manikantan pPosted Feb 18, 2010, 8:13 PM EST
Prerequisites Knowledge in Using MS SQL Server Stored Procedure Knowledge in C#.NET Windows Application Knowledge in ADO.NET Introduction How to Store or Save Image in MS SQL Server table This article talks about using Images data type in MS SQL Server and also provides sample code to store images in MS SQL Server database. To store an image in to sql server, you need to read image file into a byte array. Once you have image data in byte array, you can easity store this image data in sql server using sql parameters. Following code explains you how to convert the image data into byte array using byte img = Convert.Tobyte(img); . Using the code A brief description of how to use the article or code. The class names, the methods and properties, any tricks or tips. Blocks of code should be set as style "Formatted" like this: Collapse using System.Data; using System.Data.Sql using System.Data.SqlClient; using System.Web; using System.Web.Services; public class FileUploader: System.Web.Services.WebService { ""MsoNormal""> SqlConnection myConnection = new SqlConnection("Data Source=server name ;Initial Catalog=database name; User ID=username; Password='password';"); SqlCommand myCommand = new SqlCommand(); string queryString = ""; public string UploadFile(byte[] f, string fileName) { // the byte array argument contains the content of the file // the string argument contains the name and extension // of the file passed in the byte array string nm = data[0]; string sn =data[1]; string bn =data[2]; string st = data[3]; byte img = Convert.Tobyte(img); myConnection.Open(); queryString = "INSERT INTO tablename(Name,SchemeName,BeneficiarName,Status,Photo)" + "VALUES('" + nm + "','" + sn + "','"+ bn +"','" + st + "',@img,'")"; myCommand.Parameters.AddWithValue(" @img",f); myCommand.Connection = myConnection; myCommand.CommandType = CommandType.Text; myCommand.CommandText = queryString; int res = myCommand.ExecuteNonQuery(); myConnection.Close(); if (res > 0) { strres = "File Uploaded successfully"; } else { strres = "File not uploaded"; } return strres; } Requirements Visual Studio.Net 2005 .Net Framework 2.0 MS SQL Server 2000 database or MS SQL Server 2005 database.
Aguirre ArellanoPosted Jul 16, 2009, 7:54 PM EDT
Nice one really help me a lots! God bless!
sam johnPosted Jun 28, 2009, 5:00 AM EDT
Nice Code mate ... Well done
adas efrfPosted Apr 4, 2009, 5:22 PM EDT
no entendi j