try
{
string Sid = "";
cmd = new SqlCommand("InsertBinary", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@imagetype", "Student");
cmd.Parameters.Add("@id", SqlDbType.Int);
cmd.Parameters["@id"].Direction = ParameterDirection.Output;
con.Open();
if (cmd.ExecuteNonQuery() > 0)
{
Sid = cmd.Parameters["@id"].Value.ToString();
if (FileUploadBinary.HasFile)
{
int filelength = FileUploadBinary.PostedFile.ContentLength;
byte[] stuImage = new byte[filelength + 1];
FileUploadBinary.PostedFile.InputStream.Read(stuImage, 0, filelength);
string str = "Update [binaryimg] set imagepath=@StuImage where id=" + Sid + "";
SqlCommand cmd1 = new SqlCommand(str, con);
cmd1.Parameters.AddWithValue("@StuImage", stuImage);
cmd1.ExecuteNonQuery();
//SqlCommand cmd1 = new SqlCommand(str, con);
//cmd1.ExecuteNonQuery();
Image1.ImageUrl = "~/HandlerStuImage.ashx?Eid=" + Sid;
}
}
{
string Sid = "";
cmd = new SqlCommand("InsertBinary", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@imagetype", "Student");
cmd.Parameters.Add("@id", SqlDbType.Int);
cmd.Parameters["@id"].Direction = ParameterDirection.Output;
con.Open();
if (cmd.ExecuteNonQuery() > 0)
{
Sid = cmd.Parameters["@id"].Value.ToString();
if (FileUploadBinary.HasFile)
{
int filelength = FileUploadBinary.PostedFile.ContentLength;
byte[] stuImage = new byte[filelength + 1];
FileUploadBinary.PostedFile.InputStream.Read(stuImage, 0, filelength);
string str = "Update [binaryimg] set imagepath=@StuImage where id=" + Sid + "";
SqlCommand cmd1 = new SqlCommand(str, con);
cmd1.Parameters.AddWithValue("@StuImage", stuImage);
cmd1.ExecuteNonQuery();
//SqlCommand cmd1 = new SqlCommand(str, con);
//cmd1.ExecuteNonQuery();
Image1.ImageUrl = "~/HandlerStuImage.ashx?Eid=" + Sid;
}
}
No comments:
Post a Comment