Insert:
string strImageFileExt;
string imageName;
if (fuProductImage.FileName.ToString().Trim() != "")
{
strImageFileExt = fuProductImage.FileName.Substring(fuProductImage.FileName.LastIndexOf(".") + 1).ToLower();
imageName = ddlMovieName.SelectedItem.Text.Trim()+ "." + strImageFileExt;;
Save(imageName);
}
string strtest = "insert into Abirami_MovieDetails values('" + ddlMovieName.SelectedItem.Text.Trim() + "','" + imageName + "')";
SqlCommand sqlCmd = new SqlCommand(strtest, conn);
sqlCmd.ExecuteNonQuery();
Save Image Function:
private void Save(string imageName)
{
if (imageName != null && imageName.Trim() != "")
{
System.Drawing.Image objImage = null;
if (fuProductImage.HasFile)
{
objImage = System.Drawing.Image.FromStream(fuProductImage.FileContent);
System.Drawing.Image objSmallImage = objImage.GetThumbnailImage(161, 206, objTIA, IntPtr.Zero);
objSmallImage.Save(Server.MapPath("../AbiramiImages/" + imageName.Trim().Replace(" ", " ").Replace(" ", "_").Replace(":", "_").Replace("(", "_").Replace(")", "_")));
}
}
}
select:
SqlCommand cmd = new SqlCommand("select V_MovieProducer,V_MovieDirector,V_MovieMusicDirector,V_MovieWriter,V_MovieCast,V_MovieImage,V_Synopsis,V_StartDate,V_EndDate from Abirami_MovieDetails where V_MovieName='" + ddlMovieName.SelectedItem.Text.Trim() + "'", conn);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
txtProducer.Text = dr["V_MovieProducer"].ToString();
strImage = "../AbiramiImages/" + dr["V_MovieImage"].ToString().Trim();
if (System.IO.File.Exists(Server.MapPath(strImage)) == true)
{
Image1.ImageUrl = strImage;
}
else
{
Image1.ImageUrl = "../MovieImages/Image_Not_Available.gif";
}
}
dr.Close();
No comments:
Post a Comment