Stored Procedure code:
ALTER PROCEDURE [dbo].[imgupload]
@ProfilePictureName nvarchar(255),
@ProfilePicture varbinary(MAX),
@ProfilePicSize int,
@NewId int
as
begin
update tblUserProfile set ProfilePicture=@ProfilePicture, ProfilePictureName=@ProfilePictureName,ProfilePicSize=@ProfilePicSize where UserSignUpId=@NewId
select 1
end
Page_load :
if(Request.QueryString["Mode"]=="Updt")
{
using (dbEntities sc = new dbEntities ())
{
Int64 userid = Int64.Parse(new StandardModule().Decrypt(HttpUtility.UrlDecode(Request.QueryString["uid"])).ToString());
GetUserDetails(Int64.Parse(new StandardModule().Decrypt(HttpUtility.UrlDecode(Request.QueryString["uid"])).ToString()));
var query = sc.tblUserProfiles.FirstOrDefault(d => d.UserSignUpId == userid);
query.Email = email;
query.ProfileName = profilename;
query.UserName = username;
query.BioData = bio;
sc.SaveChanges();
}
}
Update_Profile Picture:
<pre> protected void btnUpdateProfile_Click(object sender, EventArgs e)
{
HttpPostedFile postedfile = FileUpload1.PostedFile;
string fileName = Path.GetFileName(postedfile.FileName);
string fileExtension = Path.GetExtension(fileName);
int fileSize = postedfile.ContentLength;
if (fileExtension.ToLower() == ".jpg")
{
Stream stream = postedfile.InputStream;
BinaryReader binaryReader = new BinaryReader(stream);
byte[] bytes = binaryReader.ReadBytes((int)stream.Length);
string cs = ConfigurationManager.ConnectionStrings["cnstr"].ConnectionString;
using (SqlConnection con = new SqlConnection(cs))
{
SqlCommand cmd = new SqlCommand("imgupload", con);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter paramName = new SqlParameter()
{
ParameterName = "@ProfilePictureName",
Value = fileName
};
cmd.Parameters.Add(paramName);
SqlParameter paramSize = new SqlParameter()
{
ParameterName = "@ProfilePicSize",
Value = fileSize
};
cmd.Parameters.Add(paramSize);
SqlParameter paramImage = new SqlParameter()
{
ParameterName = "@ProfilePicture",
Value = bytes
};
cmd.Parameters.Add(paramImage);
SqlParameter paramNewId = new SqlParameter()
{
ParameterName = "@NewId",
Value = Int64.Parse(Request.QueryString["uid"])
};
cmd.Parameters.Add(paramNewId);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
string uid = HttpUtility.UrlEncode(new StandardModule().Encrypt(Session["userid"].ToString()));
Response.Redirect(string.Format("~/User/UserProfile.aspx?Mode=Updt&uid={0}",uid),false);
}
}
}
What I have tried:
The Problem is not inserting into database at the particular Id of the user instead of it the image insert into new row.
Please Help me.
The error is in line
SqlParameter paramNewId = new SqlParameter()
{
ParameterName = "@NewId",
Value = Int64.Parse(Request.QueryString["uid"])
};
ie input string was not in the correct format.