manikantan p
Member since Feb 19, 2010 India
Total Visits: 14
Read Count: 00 Liked: 0
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.AddWithValu