you talk about 2 different task once the user click the button here call a method to check for the user is logged in or not which return a Boolean then check for this return if true go on and save the data otherwise redirect to log in page
additional information copied from redundant solution 2 by same person after comment from OP
if you mean by number 1 the quantity , try to save it to variable and the convert it to string or use the following
"insert into savetable(userid,productid,Quantity) values(" + Userid.Value.tostring() + "," + str+ "," + 1.tostring() + ") ";