How to retrieve image without using generic handler.
imagestore method successfully store all image for binary format.But not retrieve
one image store at a time retrieve the single image for particular location.How its help me.
protected void imagestore()
{
try
{
using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["IHPDB"].ConnectionString))
{
string empId = Session["LoggedInEmployeeId"].ToString();
SqlCommand cmd = new SqlCommand("Asp_TBLLandImage", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@TRNID", SqlDbType.Int).Value = ImageTrnid.Value != "" ? Convert.ToInt32(ImageTrnid.Value) : 0;
cmd.Parameters.Add(new SqlParameter("@PropertyTRNID", String.IsNullOrEmpty(PropTrnid.Value) ? DBNull.Value : (object)PropTrnid.Value));
Byte[] imgByte1 = null;
Byte[] imgByte2 = null;
Byte[] imgByte3 = null;
Byte[] imgByte4 = null;
if (FileUpload9.HasFile && FileUpload9.PostedFile != null)
{
HttpPostedFile File = FileUpload9.PostedFile;
imgByte1 = new Byte[File.ContentLength];
File.InputStream.Read(imgByte1, 0, File.ContentLength);
cmd.Parameters.Add("Land", SqlDbType.VarBinary).Value = imgByte1;
// con.open();
//int id = Convert.ToInt32(cd.ExecuteScalar());
//lblStatus.Text = String.Format("ID is {0}", id);
//Image1.ImageUrl = "~/DisplayImg.ashx?id=" + id;
//con.close();
}
else
{
cmd.Parameters.Add("@Land", System.Data.SqlDbType.VarBinary).Value = DBNull.Value;
}
if (FileUpload10.HasFile && FileUpload10.PostedFile != null)
{
HttpPostedFile File = FileUpload10.PostedFile;
imgByte2 = new Byte[File.ContentLength];
File.InputStream.Read(imgByte2, 0, File.ContentLength);
cmd.Parameters.Add("@MasterPlan", SqlDbType.VarBinary).Value = imgByte2;
// con.open();
//int id = Convert.ToInt32(cd.ExecuteScalar());
//lblStatus.Text = String.Format("ID is {0}", id);
//Image2.ImageUrl = "~/DisplayImg.ashx?id=" + id;
//con.close();
}
else
{
cmd.Parameters.Add("@MasterPlan", System.Data.SqlDbType.VarBinary).Value = DBNull.Value;
}
if (FileUpload11.HasFile && FileUpload11.PostedFile != null)
{
HttpPostedFile File = FileUpload11.PostedFile;
imgByte3 = new Byte[File.ContentLength];
File.InputStream.Read(imgByte3, 0, File.ContentLength);
cmd.Parameters.Add("@LocationMap", SqlDbType.VarBinary).Value = imgByte3;
}
else
{
cmd.Parameters.Add("@LocationMap", System.Data.SqlDbType.VarBinary).Value = DBNull.Value;
}
if (FileUpload12.HasFile && FileUpload12.PostedFile != null)
{
HttpPostedFile File = FileUpload12.PostedFile;
imgByte4 = new Byte[File.ContentLength];
File.InputStream.Read(imgByte4, 0, File.ContentLength);
cmd.Parameters.Add("@Others", SqlDbType.VarBinary).Value = imgByte4;
}
else
{
cmd.Parameters.Add("@Others", System.Data.SqlDbType.VarBinary).Value = DBNull.Value;
}
cmd.Parameters.Add("@UserID", SqlDbType.Int).Value = Convert.ToInt32(empId);
con.Open();
cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
Page.ClientScript.RegisterStartupScript(this.GetType(), "test", "alert('Image successfully saved!');", true);
// cmd.Parameters.Add("@TRNID", SqlDbType.Int).Value = CStatusTrnid.Value != "" ? Convert.ToInt32(CStatusTrnid.Value) : 0;
if ((String.IsNullOrEmpty(ImageTrnid.Value) ? 0 : Convert.ToInt32(ImageTrnid.Value)) == 0)
{
SqlCommand CustId = new SqlCommand("Select IDENT_CURRENT('TBLLandImage') AS TRNID", con);
SqlDataReader reader = CustId.ExecuteReader();
if (reader.HasRows)
{
while (reader.Read())
{
PropTrnid.Value = reader["TRNID"].ToString();
}
}
reader.Close();
}
con.Close();
}
}
catch (SqlException ex)
{
Console.WriteLine("SQL Error" + ex.Message.ToString());
}
}
Loading
venky nPosted Apr 1, 2015, 2:13 AM
SenzeyePosted Mar 31, 2015, 9:56 AM
http://dotnetdrizzles.blogspot.in/2014/09/image-insert-upload-bind-gridview-using.html
http://screenshotdrizzles.blogspot.in/2014/10/image-insert-upload-bind-gridview-using.html