Click here to Skip to main content
15,891,657 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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#.
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.");
        }
        
        {

        }
    }
}
Posted
Updated 25-Apr-13 4:12am
v2
Comments
ZurdoDev 25-Apr-13 9:56am    
Haven't you posted this a bunch of times? What exactly is the issue?
Computer Wiz99 25-Apr-13 10:13am    
I might have posted it a bunch but I have changed the code may times. What I am doing, I am trying to have a site that can register a user based on if that user has a profile. One database, Four tables. Table 1 has the registration data that the user will have to input. Table 2 is the CEO table that has the CEO profile already in it. This table has everything about the user like first, last, middle names and other things for that user. Table 3 is the user table. It has a user that the CEO can make up. This user can login as a user for just the profile it is linked to. The fourth one is to see if the CEO exist in table 2. If it does the the CEO can login and if it doesn't the CEO can not. Please help. I have been doing this for six weeks!!
ZurdoDev 25-Apr-13 10:17am    
There are lots of us who would love to help but I still don't understand where you are stuck. You explained what you want but didn't say what is not working.
Computer Wiz99 25-Apr-13 10:24am    
The thing that is wrong is that I have my connections in my code and it builds with no errors and it runs but it does not insert new data or update data into my tables. I can register a user and login but the users profile is not updated with the new data. I am just trying to see what I did wrong from someone else eyes on the code.
[no name] 25-Apr-13 11:16am    
Why? You have already been told what the problem is but you do not listen.

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