I am trying to connect a database with two tables. One table has the registration data and the other has the profile data. What I mean by profile is that it has the First name, Last name, Middle name and so on. I would like for the registration data to connect to the profile table so the user can see their profile information. I am using ASP.NET in C#.
using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
public partial class Registration : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["Test1ConnectionString"].ConnectionString);
con.Open();
string cmdStr = "Select count(*) from Registration where UserName='" + TextBoxEA.Text + "'";
SqlCommand userExist = new SqlCommand(cmdStr, con);
SqlCommand cmd = new SqlCommand("select * from Registration", con);
SqlDataReader dr;
dr = cmd.ExecuteReader(CommandBehavior.SingleResult);
while (dr.Read())
{
} dr.Close();
SqlCommand insertcmd = new SqlCommand("insert into TableCEO", con);
SqlDataAdapter dap = new SqlDataAdapter(insertcmd);
int temp = Convert.ToInt32(userExist.ExecuteScalar().ToString());
con.Close();
if (temp == 1)
{
Response.Write("User Name Already Exist!!!<br /> Please Choose Another User Name.");
}
}
}
protected void Submit_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Test1ConnectionString"].ConnectionString);
con.Open();
string insCmd = "Insert into Registration (UserName, Prefix, FirstName, LastName, EmailAddress, Password) values (@UserName, @Prefix, @FirstName, @LastName, @EmailAddress, @Password)";
SqlCommand insertUser = new SqlCommand(insCmd, con);
insertUser.Parameters.AddWithValue("@UserName", TextBoxEA.Text);
insertUser.Parameters.AddWithValue("@Prefix", TextBoxPR.Text);
insertUser.Parameters.AddWithValue("@FirstName", TextBoxFN.Text);
insertUser.Parameters.AddWithValue("@LastName", TextBoxLN.Text);
insertUser.Parameters.AddWithValue("@EmailAddress", TextBoxEA.Text);
insertUser.Parameters.AddWithValue("@Password", TextBoxPass.Text);
SqlCommand cmd = new SqlCommand("Insert into TableCEO (LastName, FirstName, Prefix, EmailAddress) values (@LastName, @FirstName, @Prefix, @EmailAddress)");
new SqlCommand(insCmd, con);
SqlCommand insertcmd = new SqlCommand("insert into TableCEO", con);
SqlDataAdapter dap = new SqlDataAdapter(insertcmd);
{
insertUser.ExecuteNonQuery();
con.Close();
Response.Redirect("Login.aspx");
}
{
Response.Write("Something Really Bad Has Happened....Please Try Again.");
}
{
}
}
}