-2
 protected void Button3_Click(object sender, EventArgs e)
    {
    UserStore<IdentityUser> userStore = new UserStore<IdentityUser>();
    userStore.Context.Database.Connection.ConnectionString =
       System.Configuration.ConfigurationManager.ConnectionStrings
     ["db1ConnectionString"].ConnectionString;

    UserManager<IdentityUser> manager = new UserManager<IdentityUser>
    (userStore);
    //create new user and try to store in db
    IdentityUser user = new IdentityUser();
    user.UserName = txtUserName.Text;
    user.Email = txtEmail.Text;
    user.PhoneNumber = txtPhNo.Text;    

    if (txtPassword.Text == txtConfirmPassword.Text)
    {
        try
        {
            //create user object.
            //DB will be created /expanded automatically.
            IdentityResult result = manager.Create(user, txtPassword.Text);
            if (result.Succeeded)
            {
                **UserInformation1 info = new UserInformation1
                {
                    Address = txtAddress.Text,
                    FirstName = txtFirstName.Text,
                    LastName = txtLastName.Text,
                    PostalCode = Convert.ToInt32(txtPostalCode.Text),
                    PhoneNo = Convert.ToInt32(txtPhNo.Text),

                    Email = user.Email,
                    GUID = user.Id
                };
                UserInfoModel model = new UserInfoModel();
                model.InsertUserInformation(info);**
                //store user in db
                var authenticationManager = 
                HttpContext.Current.GetOwinContext().Authentication;

                //set to log in new user by cookie
                var userIdentity = manager.CreateIdentity(user, 
                DefaultAuthenticationTypes.ApplicationCookie);
                //log in the new user and redirect to homepage
                authenticationManager.SignIn(new 
 Microsoft.Owin.Security.AuthenticationProperties(), userIdentity);
                Response.Redirect("~/Pages/greetings_home.aspx");



            }
            else
            {
                litStatus.Text = result.Errors.FirstOrDefault();
            }
        }
        catch (Exception ex)
        {
            litStatus.Text = ex.ToString();
        }

    }
    else
    {
        litStatus.Text = "Password must match";
    }
    }

error: System.OverflowException: Value was either too large or too small for an Int32. at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) at System.Convert.ToInt32(String value) at Pages_register.Button3_Click(Object sender, EventArgs e) in c:\Users\shreya\Documents\Visual Studio 2015\Project_Greetings\Pages\register.aspx.cs:line 38 My model class

public partial class UserInformation1
{
public int Id { get; set; }
public string GUID { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Address { get; set; }
public Int32 PostalCode { get; set; }
public Int32 PhoneNo { get; set; }
public string Email { get; set; }
} 

Any Solution for this error

Mickey
  • 27
  • 1
  • 4
  • What about the error do you not understand? – TZHX May 13 '17 at 19:02
  • 1
    I'm sorry but what is the question here? If you try to store a too small or a too large value into an `Int32` variable, you'll get that error from `Convert.ToInt32`. Why on earth would you use an int to store a phone number? **Use a string!** It's not a numeric value, it's a series of numeric digits. – Lasse V. Karlsen May 13 '17 at 19:07
  • `Int32` has an upper limit of 2,147,483,647. Phone numbers, depending on international area code and local formats, could conceivably have a much higher max range like 999,999,999,999. Yeah, it's going to overflow. You shouldn't be storing a phone number as an `int` anyway. Same with the zip code. If you aren't doing math on it, store it as a string. – Abion47 May 13 '17 at 19:18
  • and for Postal Code??? – Mickey May 13 '17 at 19:20

1 Answers1

1

Use string type to store the phone numbers and postal codes

https://stackoverflow.com/a/23637154

But to avoid this exception you can use int.TryParse():

int result;
if(!int.TryParse(txtPostalCode.Text, out result))
{
    // process wrong input
}
Community
  • 1
  • 1
Vitali
  • 645
  • 9
  • 14