Click here to Skip to main content
15,914,225 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Greetings. I am using ASP.net on VS 2010 and came to this block. I have three databases in this project. The first is a registration database and the others have data in them but need to be read crossed with the registration one for the user side to see if the user exist.

Here is my code:
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(ConfigurationManager.ConnectionStrings["Test1ConnectionString"].ConnectionString);
            SqlConnection con1 = new SqlConnection(ConfigurationManager.ConnectionStrings["CEOConnectionString"].ConnectionString);
            SqlConnection con2 = new SqlConnection(ConfigurationManager.ConnectionStrings["IALOConnectionString"].ConnectionString);
            con.Open();
            con1.Open();
            
            string cmdStr = "Select count(*) from Registration where UserName='" + TextBoxEA.Text + "'";
            SqlCommand userExist = new SqlCommand(cmdStr, con);
            new SqlCommand(cmdStr, con1);
            new SqlCommand(cmdStr, con2);
            int temp = Convert.ToInt32(userExist.ExecuteScalar().ToString());
            con.Close();
            con1.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);
        SqlConnection con1 = new SqlConnection(ConfigurationManager.ConnectionStrings["CEOConnectionString"].ConnectionString);
        SqlConnection con2 = new SqlConnection(ConfigurationManager.ConnectionStrings["IALOConnectionString"].ConnectionString);
        con.Open();
        con1.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);

        //con1.Open();
        //SqlCommand cmd = new SqlCommand("Insert into COCCEO (LastName, FirstName, Prefix, EmailAddress) values (@LastName, @FirstName, @Prefix, @EmailAddress");
        //new SqlCommand(insCmd, con1);
        //insertUser.Parameters.AddWithValue("@LastName", TextBoxLN.Text);
        //insertUser.Parameters.AddWithValue("@FirstName", TextBoxFN.Text);
        //insertUser.Parameters.AddWithValue("@Prefix", TextBoxPR.Text);
        //insertUser.Parameters.AddWithValue("@EmailAddress", TextBoxEA.Text);
             
         try
        {
            insertUser.ExecuteNonQuery();
            con.Close();
            con1.Close();

            Response.Redirect("Login.aspx");
        }
        catch (Exception er)
        {
            Response.Write("Something Really Bad Has Happened....Please Try Again.");
        }
        finally
        {

        }
    }
}
Posted
Updated 23-Apr-13 8:58am
v2
Comments
ZurdoDev 23-Apr-13 15:02pm    
What's your question?
Computer Wiz99 23-Apr-13 16:03pm    
What did I do wrong that the program doesn't take me to the next page? And why does the data that is entered is not writing to any of my connections? How can I take data from a registration page and have it saved and updated to three database tables?

Thanks In Advance!
ZurdoDev 23-Apr-13 16:23pm    
Just put a breakpoint and see what is happening.
Computer Wiz99 23-Apr-13 16:27pm    
Ok. Is there a special place to put that? Just to make sure.
ZurdoDev 23-Apr-13 16:32pm    
Not really. Just say it isn't working so that is kind of vague as to what the issue is. I would just put a breakpoint on the first line of the event and see what is happening.

1 solution

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
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Test1ConnectionString"].ConnectionString);
SqlConnection con1 = new SqlConnection(ConfigurationManager.ConnectionStrings["CEOConnectionString"].ConnectionString);
SqlConnection con2 = new SqlConnection(ConfigurationManager.ConnectionStrings["IALOConnectionString"].ConnectionString);

protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{

}
}
}

// this you declare your sqlconnection
 
Share this answer
 

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