USE [Souvik]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Test](
[Sln] [int] IDENTITY(1,1) NOT NULL,
[Name] [varchar](50) NULL,
[Address] [varchar](50) NULL,
[Photo] [image] NULL,
CONSTRAINT [PK_Test] PRIMARY KEY CLUSTERED
(
[Sln] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
//////////////////////////////////////////////////////////////////////////
Store Procedure
----------------
USE [Souvik]
GO
/****** Object: StoredProcedure [dbo].[sp_Insert_Into_Test] Script Date: 09/04/2012 14:38:36 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <author,,name>
-- Create date: <create>
-- Description: <description,,>
-- =============================================
ALTER PROCEDURE [dbo].[sp_Insert_Into_Test]
-- Add the parameters for the stored procedure here
@Name varchar(50),
@Address varchar(50),
@Photo image
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
insert into Test(Name,Address,Photo) values(@Name,@address,@Photo)
END
///////////////////////////////////////////////////////////////////////////////
Asp.net
-------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.IO;
public partial class Test : System.Web.UI.Page
{
string str = "Data Source=SOUVIK-PC;Initial Catalog=Souvik;User ID=sa;Password=123456";
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnUploadData_Click(object sender, EventArgs e)
{
try
{
SqlConnection con = new SqlConnection(str);
SqlCommand com = new SqlCommand("sp_Insert_Into_Test", con);
com.CommandType = CommandType.StoredProcedure;
com.Parameters.Add("@Name", SqlDbType.VarChar).Value = txtName.Text;
com.Parameters.Add("@Address", SqlDbType.VarChar).Value = txtAddress.Text;
{
if (FileUpload1.PostedFile != null &&
FileUpload1.PostedFile.FileName != "")
{
byte[] imageSize = new byte
[FileUpload1.PostedFile.ContentLength];
HttpPostedFile uploadedImage = FileUpload1.PostedFile;
uploadedImage.InputStream.Read
(imageSize, 0, (int)FileUpload1.PostedFile.ContentLength);
SqlParameter UploadedImage = new SqlParameter("@Photo", SqlDbType.Image, imageSize.Length);
UploadedImage.Value = imageSize;
com.Parameters.Add(UploadedImage);
}
}
con.Open();
com.ExecuteNonQuery();
Label4.Text = "Inserted";
con.Close();
}
catch (Exception ex)
{
}
}
}