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;
public partial class Account_Register : System.Web.UI.Page
{
string connStr = ConfigurationManager.ConnectionStrings["aspnetdbConnectionString"].ToString();
protected void Page_Load(object sender, EventArgs e)
{
}
protected void CreateUserButton_Click(object sender, EventArgs e)
{
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();
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;
}
if (newUser != null)
{
MembershipUser objSql = Membership.GetUser();
object userGUID = objSql.ProviderUserKey.ToString();
}
}
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()
{
}
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
{
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();
}
}
}
}