Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
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
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
 
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 5-Oct-12 5:31am

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

  Print Answers RSS
0 OriginalGriff 339
1 DineshMaind 95
2 Sergey Alexandrovich Kryukov 94
3 majid torfi 85
4 kbrandwijk 75
0 Zubair MCA 55
1 OriginalGriff 55
2 sankarsan parida 55
3 harshavardhan12345678 45
4 Sandeep Londhe 45


Advertise | Privacy | Mobile
Web02 | 2.8.140827.1 | Last Updated 5 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100