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);
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
{
}
}
}