Click here to Skip to main content
15,891,629 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.
Posted
Updated 18-Sep-17 1:51am

Hello,
Error message says that you are trying to convert the provided value into Integer which is definitely not a valid integer. so, check what is the value coming from QueryString.
Put a break point and debug it.
Thanks
 
Share this answer
 
I suggest you create full TSQL string and execute those, rather than use the functionality with various modes and such.

UPDATE [table] SET .... WHERE....

This is better not only because of readability but because that part of your work in now readily transported between languages should the need arise - and can be tested directly in tools, such as SQL Server Mgmt Studio, to make sure your query does what you want it to.

The above "UPDATE", for example, would never INSERT a new record
 
Share this answer
 
Solved:
Int64 userid = Int64.Parse(new StandardModule().Decrypt(HttpUtility.UrlDecode(Request.QueryString["uid"])).ToString());


i just decrypt the id which is coming from login page then i use it like this


SqlParameter paramNewId = new SqlParameter()
                {
                    ParameterName = "@NewId",
                    Value = userid
 
                };


and it works fine.

Thanks.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900