create userwizard and userid aspnet_users in ASPNETDB.MDF and table1 in ASPNETDB:MDF :)

Last post 05-17-2008 8:52 AM by oguzkaygun. 22 replies.

Sort Posts:

  • create userwizard and userid aspnet_users in ASPNETDB.MDF and table1 in ASPNETDB:MDF :)

    05-16-2008, 10:43 AM

    hi

    i used createuserwizard and i have a lot of table in aspnetdb.mdf related to createuserwizard :)

    i added new table in aspnetdb.mdf and new table name is table1:) table1 have productname and userid as coulumnname.. datatype of userid is uniqueidentifier.. datatype is same as userid of aspnet_users :) and data type of productname is nchar :)

    for example i login in john that jonh have created with createuserwizard before... and john have userid in aspnet_users in aspnetdb.mdf... i want to take userid data of aspnet_users to userid data of  table1 :) how can i do this ? i want to use button1 for this :) which username(john or else somebody) login in, userid related to username should be copy to userid of table1 :)

    could you write to me as visual basic code ?

    thank you for reading:)

    Mark as me if this question can be helpful :)

    cheers

    Mark as me if my question or my answer can be helpful for you :)
  • Re: create userwizard and userid aspnet_users in ASPNETDB.MDF and table1 in ASPNETDB:MDF :)

    05-16-2008, 12:24 PM
    Answer

    Here is what you need I have written it by myself but didn't try it.

    1. Protected Sub Login1_LoggedIn(ByVal sender As Object, ByVal e As EventArgs)
    2.     Dim yourUser As MembershipUser = Membership.GetUser(Login1.UserName.ToString(), True)
    3.     Dim userGuid As System.Guid = DirectCast(yourUser.ProviderUserKey, Guid)
    4.    
    5.     Dim conn As New SqlConnection(ConfigurationManager.ConnectionStrings("YourConnectionstringFromWebConfig").ConnectionString)
    6.     Dim cmd As New SqlCommand("Insert into table1 (Id,product) VALUES (@Id, @product)", conn)
    7.     'you should use sproc instead
    8.     cmd.Parameters.AddWithValue("@Id", userGuid)
    9.     cmd.Parameters.AddWithValue("@product", "...")
    10.     'your value
    11.     Try
    12.         conn.Open()
    13.         Dim rows As Int32 = cmd.ExecuteNonQuery()
    14.         conn.Close()
    15.         Trace.Write(String.Format("You have {0} rows inserted successfully!", rows.ToString()))
    16.     Catch sex As SqlException
    17.        
    18.         Throw sex
    19.     Finally
    20.         If conn.State <> ConnectionState.Closed Then
    21.             conn.Close()
    22.         End If
    23.     End Try
    24.    
    25. End Sub

     

    Please: Don't forget to click "Mark as Answer" on the post that helped you. That way future readers will know which post solved your issue.
  • Re: create userwizard and userid aspnet_users in ASPNETDB.MDF and table1 in ASPNETDB:MDF :)

    05-16-2008, 12:43 PM
    Answer

    hello

    thank you for your help :) pls go on help me :)

    i click button1 when i have clicked login button in login1 after i write to username and password, there is error... program stops

    but i click button1 when i have write to username and password without clicking login... i see  dc996ee5-9f7d-4763-a758-c4dfd1a0bef9 :)

    what is it ?? is it userid ??

    and how can i do this after clicking login button in login1

    my code is below

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

    Dim yourUser As MembershipUser = Membership.GetUser(Login1.UserName.ToString(), True)

    Dim userGuid As System.Guid = DirectCast(yourUser.ProviderUserKey, Guid)

    TextBox4.Text = userGuid.ToString    ' if there is no tostring, userGuid have underline

    End Sub

    Mark as me if my question or my answer can be helpful for you :)
  • Re: create userwizard and userid aspnet_users in ASPNETDB.MDF and table1 in ASPNETDB:MDF :)

    05-16-2008, 12:50 PM
    Answer

     This is the userid it is called a guid or in sql uniqueidentifier. How you can call in on button1_click. Put my code just under the button1_click method.

    To convert guid to string use the convert class:

    Convert.toString(userguid) 

    Please: Don't forget to click "Mark as Answer" on the post that helped you. That way future readers will know which post solved your issue.
  • Re: create userwizard and userid aspnet_users in ASPNETDB.MDF and table1 in ASPNETDB:MDF :)

    05-16-2008, 12:56 PM

    hello

    but it will not work in my different page.aspx.. after any username login, and when username insert product from page.aspx, it should be work.. but when i click login button from login1, there is error :) it doesnt work..it works with button1 before i click login button from login1 :)

    cheers

     

    Mark as me if my question or my answer can be helpful for you :)
  • Re: create userwizard and userid aspnet_users in ASPNETDB.MDF and table1 in ASPNETDB:MDF :)

    05-16-2008, 1:06 PM
    Answer

    What is the error? 

    Please: Don't forget to click "Mark as Answer" on the post that helped you. That way future readers will know which post solved your issue.
  • Re: create userwizard and userid aspnet_users in ASPNETDB.MDF and table1 in ASPNETDB:MDF :)

    05-16-2008, 1:15 PM

    hello

    thank you for your help :)

    after i click login button from login1, i click button1 and i have error..but i should click button1 from new page.aspx after i click login button from login1 in different page.aspx

    error code line is

    Dim userGuid As System.Guid = DirectCast(yourUser.ProviderUserKey, Guid)

    error dialog box is NullReferenceException was unhandled by user code

    cheers

    Mark as me if my question or my answer can be helpful for you :)
  • Re: create userwizard and userid aspnet_users in ASPNETDB.MDF and table1 in ASPNETDB:MDF :)

    05-16-2008, 1:40 PM
    Answer

    Ahh you want to call the code from another page? Then you need to do the following things on the site where the login control is:

    Protected Sub Login1_LoggedIn(ByVal sender As Object, ByVal e As EventArgs)

    response.redirect(String.Format("page2.aspx?user={0}",Login1.Username)); 

    End sub

    On the other page to the following:

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)

    If Request.Querystring is nothing then

        exit sub 

    end if
    Dim yourUser As MembershipUser = Membership.GetUser(Request.Querystring("user"), True)
    Dim userGuid As System.Guid = DirectCast(yourUser.ProviderUserKey, Guid)
       
    Dim conn As New SqlConnection(ConfigurationManager.ConnectionStrings("YourConnectionstringFromWebConfig").ConnectionString)
     Dim cmd As New SqlCommand("Insert into table1 (Id,product) VALUES (@Id, @product)", conn) 'you should use sproc instead
     cmd.Parameters.AddWithValue("@Id", userGuid)
     cmd.Parameters.AddWithValue("@product", "...") 'your value
    Try
    conn.Open()
     Dim rows As Int32 = cmd.ExecuteNonQuery()
    conn.Close()
    Trace.Write(String.Format("You have {0} rows inserted successfully!", rows.ToString()))
    Catch sex As SqlException
           
    Throw sex
    Finally

    If conn.State <> ConnectionState.Closed Then
    conn.Close()
    End If

     End Try
     
     End Sub

    Please: Don't forget to click "Mark as Answer" on the post that helped you. That way future readers will know which post solved your issue.
  • Re: create userwizard and userid aspnet_users in ASPNETDB.MDF and table1 in ASPNETDB:MDF :)

    05-16-2008, 2:04 PM

    hello

    it works perfect :)

    but what will happen if i insert userid with username and gender and phone nunmber etc. ???

    chers

    Mark as me if my question or my answer can be helpful for you :)
  • Re: create userwizard and userid aspnet_users in ASPNETDB.MDF and table1 in ASPNETDB:MDF :)

    05-16-2008, 2:09 PM
    Answer

    You need to add the columns into your table and add them to the insert statement with the fitting parameters thats all.  

    Please: Don't forget to click "Mark as Answer" on the post that helped you. That way future readers will know which post solved your issue.
  • Re: create userwizard and userid aspnet_users in ASPNETDB.MDF and table1 in ASPNETDB:MDF :)

    05-16-2008, 2:24 PM

     

    thank you for your all help :)

    i just added

    TextBox5.Text = yourUser.UserName

    TextBox6.Text = yourUser.Email

    and it works :)

    cheers

    Mark as me if my question or my answer can be helpful for you :)
  • Re: create userwizard and userid aspnet_users in ASPNETDB.MDF and table1 in ASPNETDB:MDF :)

    05-16-2008, 2:25 PM
    Answer

    Fine have fun

    Please: Don't forget to click "Mark as Answer" on the post that helped you. That way future readers will know which post solved your issue.
  • Re: create userwizard and userid aspnet_users in ASPNETDB.MDF and table1 in ASPNETDB:MDF :)

    05-16-2008, 2:56 PM

     

    hi again :) i have marked as all your message :) and i have new problem :) do you have any idea for my new problem ?:)

    when i click login button from login1, i go default2.aspx and my button1 code is run...login button code line is below

    Protected Sub Login1_Authenticate(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.AuthenticateEventArgs) Handles Login1.Authenticate

    Response.Redirect(String.Format("default2.aspx?user={0}", Login1.UserName))

    End Sub

    but i dont want to go default2.aspx when i click login button from login1...and  i change default2.aspx?user={0} to default.aspx?user={0} so i dont go to default2.aspx and i can stay default.aspx ...

    when i go to default2.aspx with hyperlink of my menu bar, my button1 doesnt work and give me error :) i should go default2.aspx after i show around default3.aspx and default4.aspx etc.

    my button1 of default2.aspx code is below

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

    If Request.QueryString Is Nothing Then

    Exit Sub

    End If

    Dim yourUser As MembershipUser = Membership.GetUser(Request.QueryString("user"), True) ' it is error code line.. error is ArgumentNullException was unhandled by user code

    Dim userGuid As System.Guid = DirectCast(yourUser.ProviderUserKey, Guid)

    TextBox4.Text = Convert.ToString(userGuid)

    TextBox5.Text = yourUser.UserName

    TextBox6.Text = yourUser.Email

    End Sub

    cheers

    Mark as me if my question or my answer can be helpful for you :)
  • Re: create userwizard and userid aspnet_users in ASPNETDB.MDF and table1 in ASPNETDB:MDF :)

    05-16-2008, 3:04 PM

    Put a link button onto your default.aspx and create the following method:

    Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As EventArgs)   

        Response.Redirect(String.Format("default2.aspx?user={0}", Login1.Username)) 

    End Sub

     

    Please: Don't forget to click "Mark as Answer" on the post that helped you. That way future readers will know which post solved your issue.
  • Re: create userwizard and userid aspnet_users in ASPNETDB.MDF and table1 in ASPNETDB:MDF :)

    05-16-2008, 3:16 PM