Click here to Skip to main content
15,895,667 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm using a Three tiered architecture to build a website. I'm working on the registration page and i need some help. When i create a new user i'm able to store the values the aspnetdb membership table where the user id is generated randomly however i want to send the values to my own table which i named it as 'Users'. I'm not really familiar with GUID function. Can somebody help me out of this one. Thanks
Sai

Here is my Presentation layer
C#
using System;
using System.Configuration;
using System.Collections.Specialized;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
//using BAL;
public partial class Account_Register : System.Web.UI.Page
{
    string connStr = ConfigurationManager.ConnectionStrings["aspnetdbConnectionString"].ToString();
   // SqlConnection objSql = new SqlConnection(connStr); 
    protected void Page_Load(object sender, EventArgs e)
    {
        //RegisterUser.ContinueDestinationPageUrl = Request.QueryString["ReturnUrl"];
    }
  
    protected void CreateUserButton_Click(object sender, EventArgs e)
    {
        //int getresult = 0;
        //string U_ID;

        //DataSet sql = new DataSet();
        ////SqlConnection con = new SqlConnection(connStr);
        //string F_Name = txtFirstName.Text;
        //string L_Name = txtLastName.Text; 
        //string Address = txtAddress.Text;
        //string City =txtCity.Text; 
        //string State = txtState.Text; 
        //string Zip = txtZipCode.Text; 
        //string DOB = txtDOB.Text;
        //string Phone = txtPhone.Text;
        //string email = txtEmail.Text; 
        //string User_Name = txtUserName.Text;
        //string Password = txtPassword.Text; 
        //string PasswordQuestion = txtPasswordQuestion.Text;
        //string PasswordAnswer = txtPasswordAnswer.Text;


        MembershipCreateStatus createStatus;
        MembershipUser newUser = Membership.CreateUser(txtUserName.Text, txtPassword.Text, txtEmail.Text, txtPasswordQuestion.Text, txtPasswordAnswer.Text, true, out createStatus);
        switch (createStatus)
        {
            case MembershipCreateStatus.Success:
                String UserId = newUser.ProviderUserKey.ToString(); //create provider key?
                lblCreateAccount.Text = "The user account was successfully created!";
                break;
            case MembershipCreateStatus.DuplicateUserName:
                lblCreateAccount.Text = "There already exists a user with this username.";
                break;

            case MembershipCreateStatus.DuplicateEmail:
                lblCreateAccount.Text = "There already exists a user with this email address.";
                break;
            case MembershipCreateStatus.InvalidEmail:
                lblCreateAccount.Text = "There email address you provided in invalid.";
                break;
            case MembershipCreateStatus.InvalidAnswer:
                lblCreateAccount.Text = "There security answer was invalid.";
                break;
            case MembershipCreateStatus.InvalidPassword:
                lblCreateAccount.Text = "The password you provided is invalid. It must be seven characters long and have at least one non-alphanumeric character.";

                break;
            default:
                lblCreateAccount.Text = "There was an unknown error; the user account was NOT created.";
                break;

                
                //SqlCommand cmd = new SqlCommand("INSERT INTO Users Values('" + txtFirstName.Text + "','" + txtLastName.Text + "','" + txtAddress.Text +
                //    "','" + txtCity.Text + "','" + txtState.Text + "','" + txtZipCode.Text + "','" + txtDOB.Text + "','" + txtPhone.Text + "','" + txtEmail.Text
                //    + "','" + txtUserName.Text + "','" + txtPassword.Text + "','" + txtConfirmPassword.Text + "','" + txtPasswordQuestion.Text + "','"
                //    + txtPasswordAnswer.Text + "'");

                

        }

        if (newUser != null)
                {
                    MembershipUser objSql = Membership.GetUser();
                    object userGUID = objSql.ProviderUserKey.ToString();    
            //string userid = objSql.ProviderUserKey.ToString();
            //        objSql.Insert(U_ID, F_Name, L_Name, Address, City, State, Zip, DOB, Phone,
            //email, User_Name, Password, PasswordQuestion, PasswordAnswer);

                }

        //getresult = lbl.Insert(U_ID, F_Name, L_Name, Address, City, State, Zip, DOB, Phone,
        //    email, User_Name, Password,PasswordQuestion, PasswordAnswer);
        //con.Open();
        
        //cmd.ExecuteNonQuery();

 
    }


    protected void AddRecords(object sender, EventArgs e)
    {

    }

    protected void LinkButton1_Click(object sender, EventArgs e)
    {
       

    }
}


here is my DataAccessclass

C#
using System;

using System.Data;

using System.Configuration;
using System.Collections.Specialized;
using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

using System.Data.SqlClient;

namespace DataClass
{
    public class ConnectionClass
    {
        string connStr = ConfigurationManager.ConnectionStrings["aspnetdbConnectionString"].ToString();
        public ConnectionClass()
        {  
            // Add Constructor Logic
            
        }
        
        public int Insert (string U_ID, string F_Name, string L_Name, string Address, string City, string State, string Zip, string DOB, string Phone,
            string email, string User_Name, string Password, string PasswordQuestion, string PasswordAnswer)
        {

            SqlConnection con = new SqlConnection(connStr);
            con.Open();
            SqlCommand cmd = new SqlCommand("user_membership", con);
            cmd.CommandType = CommandType.StoredProcedure;
            try {
            
            cmd.Parameters.Add("@UserId", SqlDbType.UniqueIdentifier).Value = new Guid(U_ID);
            cmd.Parameters.AddWithValue("@F_Name", F_Name);
            cmd.Parameters.AddWithValue("@L_Name", L_Name);
            cmd.Parameters.AddWithValue("@Address", Address);
            cmd.Parameters.AddWithValue("@City", City);
            cmd.Parameters.AddWithValue("@State", State);
            cmd.Parameters.AddWithValue("@Zip", Zip);
            cmd.Parameters.AddWithValue("@DOB", DOB);
            cmd.Parameters.AddWithValue("@Phone", Phone);
            cmd.Parameters.AddWithValue("@email", email);
            cmd.Parameters.AddWithValue("@User_Name", User_Name);
            cmd.Parameters.AddWithValue("@Password", Password);
            cmd.Parameters.AddWithValue("@PasswordQuestion", PasswordQuestion);
            cmd.Parameters.AddWithValue("@PasswordAnswer", PasswordAnswer);
            return cmd.ExecuteNonQuery();

            }
            catch { throw; }
            finally 
            {
               
                con.Dispose();
                con.Close();
                cmd.Dispose();
            }
            

        }

        public DataTable Load(string F_Name, string L_Name, string Address, string City, string State, string Zip, string DOB, string Phone,
            string email, string User_Name, string Password, string PasswordQuestion, string PasswordAnswer)
        {
            SqlConnection conn = new SqlConnection(connStr);

            SqlCommand cmd = new SqlCommand("user_membership", conn);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            da.SelectCommand.CommandType = CommandType.StoredProcedure;

            DataSet ds = new DataSet();
            try
            {
                // da.GetFillParameters();
                cmd.Parameters.AddWithValue("@F_Name", F_Name);
                cmd.Parameters.AddWithValue("@L_Name", L_Name);
                cmd.Parameters.AddWithValue("@Address", Address);
                cmd.Parameters.AddWithValue("@City", City);
                cmd.Parameters.AddWithValue("@State", State);
                cmd.Parameters.AddWithValue("@Zip", Zip);
                cmd.Parameters.AddWithValue("@DOB", DOB);
                cmd.Parameters.AddWithValue("@Phone", Phone);
                cmd.Parameters.AddWithValue("@email", email);
                cmd.Parameters.AddWithValue("@User_Name", User_Name);
                cmd.Parameters.AddWithValue("@Password", Password);
                cmd.Parameters.AddWithValue("@PasswordQuestion", PasswordQuestion);
                cmd.Parameters.AddWithValue("@PasswordAnswer", PasswordAnswer);
                da.Fill(ds);
                return ds.Tables[0];
            }
            catch
            {
                throw;
            }
            finally
            {
                ds.Dispose();
                da.Dispose();
                conn.Close();

                conn.Dispose();
            }
        }

    }
}
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900