locked
How to attach Userid of membership asp_user table to custom userid table RRS feed

  • Question

  • User1557098506 posted

    Hi,

    I have made two signup forms, First one is by using createuserwizard and after filling the form it takes it to sign2 form where I have added extra things like first name lastname etc.

    Now thing is I want to have one thing similar in both of the form so I was thinking userid would do this thing.

    So how can I attach Userid of createuserwizard with my sign2 form so that everything store for a paritcular user.

    Thanks

    Tuesday, June 24, 2014 8:09 AM

Answers

  • User697462465 posted

    Hi new2world,

    From your error message, I guess the Userid of your User_Information table have be constraint to User table as foreign key.

    So, the Userid of User_Information value must fetch from User table.

    Best Regards,
    Terry Guo

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, June 26, 2014 2:22 AM
  • User224181609 posted

    New2World: You should set up your database diagram and User_Information table like so:

    Your User_Information table should have UserID as primary key:

    and you should set up the relationship for UserID in the database diagram:

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, June 26, 2014 9:04 AM

All replies

  • User224181609 posted

    Look at the tables in your aspnetdb.mdf database. You will find the UserID as the primary key in the Aspnet_Users table and how it is tied to other tables such as the aspnet_usersinroles table.

    You need to do the same thing with your sign2 table -- you need the UserID to be a common key to the tables. This is normally done by setting up the Database Diagram.

    Tuesday, June 24, 2014 8:39 AM
  • User1557098506 posted

    Here is the things that I am doing right now.

    Set the  primary key to Userid in custom table and set the relationship key with asp_ user table  for userid.

    Now when I create user in create user data get enter but for custom form I am getting this error when I remove userid from sql connection insert.

    Error:System.Data.SqlClient.SqlException (0x80131904): The INSERT statement conflicted with the FOREIGN KEY constraint "FK_User_Information_aspnet_Users"F

    This is my created wizard user cs file :

    protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
        {
            MembershipUser newUser = Membership.GetUser(CreateUserWizard1.UserName);
    
            Guid newUserId = (Guid)newUser.ProviderUserKey;
    
            Response.Redirect("signup2.aspx");

    this code is in Custom table CS file :

    protected void btnsubmit_Click(object sender, EventArgs e)
        {
    
            try
            {
                Guid id = Guid.NewGuid();
                SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["userConnectionString"].ConnectionString);
                conn.Open();
                string insertQuery = " insert into User_Information ( Userid, FirstName) Values( @Userid, @FirstName)";
    
                SqlCommand com = new SqlCommand(insertQuery, conn);
                com.Parameters.AddWithValue("@Userid", id.ToString());
                com.Parameters.AddWithValue("@FirstName", txtfname.Text);

    Is there other way to have userid in my custom table cs file?

    Kindly let me know thanks

    Tuesday, June 24, 2014 11:38 AM
  • User697462465 posted

    Hi new2world,

    From your error message, I guess the Userid of your User_Information table have be constraint to User table as foreign key.

    So, the Userid of User_Information value must fetch from User table.

    Best Regards,
    Terry Guo

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, June 26, 2014 2:22 AM
  • User224181609 posted

    New2World: You should set up your database diagram and User_Information table like so:

    Your User_Information table should have UserID as primary key:

    and you should set up the relationship for UserID in the database diagram:

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, June 26, 2014 9:04 AM
  • User1557098506 posted

    Thank you so much, I was able to make the form atlast.

    Friday, June 27, 2014 3:30 PM