Dear All,
How to insert image using asp.net
I have a image field in sql table, kindly give me a solution to insert the image.
I am getting error in image field.
private int Save()
{
if (movieImage.HasFile)
{
string fileName = Path.GetFileName(movieImage.PostedFile.FileName);
movieImage.PostedFile.SaveAs(Server.MapPath("~/MovieImage/") + fileName);
Movie Evet = new Movie
{
Movie_Name = txtMovie_Name.Text,
Movie_Image = fileName,
Movie_Date = Convert.ToDateTime(txtEventDate.Value),
Movie_Time = txtEventTime.Value,
Qty = Convert.ToInt32(txtslot.Text),
Price = Convert.ToDecimal(txtSlot_price.Text),
Status = true
};
return new MovieDAL().Save(Evet);
}
}
CREATE TABLE [dbo].[Movie](
[MovieID] [int] IDENTITY(1,1) NOT NULL,
[Movie_Name] [nvarchar](100) NOT NULL,
[Movie_Image] [image] NULL,
[Movie_Date] [datetime] NOT NULL,
[Movie_Time] [nvarchar](50) NOT NULL,
[Qty] [int] NOT NULL,
[Price] [decimal](18, 3) NOT NULL,
[Status] [bit] NOT NULL,
CONSTRAINT [PK_Movie] PRIMARY KEY CLUSTERED
(
[MovieID] 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