Sundas Ali

Sundas Ali

  • NA
  • 7
  • 7k

Select image from database

Jul 19 2016 3:08 PM
<asp:Image ID="Image1" runat="server" />
cmd.CommandText = "SP_INSERT_DriverRegister";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@DriverReg_id", HF_Reg_Id.Value);
cmd.Parameters.Add("@SeatsNumbers", txtDriverSeats.Text);
//cmd.Parameters.Add("@AvailableSeats", txtDriverAvailableSeats.Text);
//cmd.Parameters.Add("@VehicleImage",??);
how to select image from database?
Insert Method
protected void Button1_Click1(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
string Extension = System.IO.Path.GetExtension(FileUpload1.FileName);
if (Extension.ToLower() != ".gif" && Extension.ToLower() != ".png" && Extension.ToLower() != ".jpg" && Extension.ToLower() != ".jpeg")
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "popup", "alert('Invalid image format');", true);
}
else
{
int FileSize = FileUpload1.PostedFile.ContentLength;
if (FileSize > 1048576)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "popup", "alert('Maximum file size 1 mb');", true);
}
else
{
string pathName = "uploadImages/" + Path.GetFileName(FileUpload1.PostedFile.FileName);
SqlConnection con = new SqlConnection(conString);
SqlCommand cmd = new SqlCommand("insert into tbl_images(images_path) values('" + pathName + "')", con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
FileUpload1.SaveAs(Server.MapPath("~/UploadImages/" + FileUpload1.FileName));
ScriptManager.RegisterStartupScript(this, this.GetType(), "popup", "alert('File Uploaded.....');", true);
}
}
}
else
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "popup", "alert('Please select a file');", true);
}
}
 
 
 

Answers (1)