Note that there are some explanatory texts on larger screens.

plurals
  1. POInsert asp.net Membership-generated UserId into custom table (vb)
    primarykey
    data
    text
    <p>I've spent a couple of hours trying to find the answer to this, and although there are tutorials all over the 'net none of them work for me (or I am too n00b to understand what they're telling me...)</p> <p>Anyway, I'm creating users in asp.net using Membership. What I want to do is add the generated UserId to a column in a custom table I've created, to link the stuff in the custom table with the user created in aspnet_Users.</p> <p>Here's the code I've got for the registration submit button:</p> <pre><code>Private Sub submit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles submit.Click Dim connectionString As String = WebConfigurationManager.ConnectionStrings("edinsec").ConnectionString Dim createStatus As MembershipCreateStatus Membership.CreateUser(fname.Text, password.Text, email.Text, sq.Text, sa.Text, False, createStatus) ''#Something has to happen here! Dim insertSQL As String insertSQL = "INSERT INTO clients (UserId)" insertSQL &amp;= "VALUES (@userId)" Using con As New SqlConnection(connectionString) Dim cmd As New SqlCommand(insertSQL, con) cmd.Parameters.AddWithValue("@firstname", firstname.Text) Try Try con.Open() Catch ex As SqlException MsgBox("Connection Problem - Please Retry Later", 65584, "Connection Error") End Try cmd.ExecuteNonQuery() MsgBox("Thank you for joining us - we will be in touch shortly.", 65600, "Join Up") Response.Redirect("Default.aspx") Catch Err As SqlException MsgBox("Error inserting record - please retry later.", 65584, "Insertion Error") End Try con.Close() End Using End Sub </code></pre> <p>As you can see I'm trying to grab the Membership-generated userid and insert it into the clients table. I've tried numerous approaches to grabbing the UserId but none work.</p> <p>Membership works to create the user, it's just the part afterwards that I'm stuck on.</p> <p>Any help would be much appreciated :)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload