Ok. Here is my new code and it does work.
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["HotConnectionString"].ConnectionString);
con.Open();
string cmdStr = "Select count(*) from Tablepass where EmailAddress='" + TextBoxEA.Text + "'";
string cmdStr2 = "Select count(*) from Table1 where EmailAddress='" + TextBoxEA.Text + "'";
string cmdStr3 = "Select count(*) from Table2 where EmailAddress='" + TextBoxEA.Text + "'";
SqlCommand userExist = new SqlCommand(cmdStr, con);
SqlCommand userExist2 = new SqlCommand(cmdStr2, con);
SqlCommand userExist3 = new SqlCommand(cmdStr3, con);
SqlCommand cmd = new SqlCommand("select INST_ID, EmailAddress from Tablepass", con);
SqlCommand cmd2 = new SqlCommand("select INST_ID, EmailAddress from Table1", con);
SqlCommand cmd3 = new SqlCommand("select INST_ID, EmailAddress from Table2", con);
userExist.Parameters.AddWithValue("@EmailAddress", TextBoxEA.Text);
userExist.Parameters.AddWithValue("@Password", TextBoxPW.Text);
userExist2.Parameters.AddWithValue("@EmailAddress", TextBoxEA.Text);
userExist2.Parameters.AddWithValue("@Password", TextBoxPW.Text);
userExist3.Parameters.AddWithValue("@EmailAddress", TextBoxEA.Text);
userExist3.Parameters.AddWithValue("@Password", TextBoxPW.Text);
int temp = Convert.ToInt32(userExist.ExecuteScalar().ToString());
int temp2 = Convert.ToInt32(userExist2.ExecuteScalar().ToString());
int temp3 = Convert.ToInt32(userExist3.ExecuteScalar().ToString());
if (temp == 1)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('User Name Already Exist!!!');", true);
TextBoxEA.Focus();
TextBoxEA.Text = string.Empty;
}
else if (temp2 == 1)
{
}
else if (temp3 == 1)
{
}
else if (temp2 == 0)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('User Name Is Not Recognized by The System!!!');", true);
TextBoxEA.Focus();
TextBoxEA.Text = string.Empty;
}
else if (temp3 == 0)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('User Name Is Not Recognized by The System!!!');", true);
TextBoxEA.Focus();
TextBoxEA.Text = string.Empty;
}
con.Close();
}
}
protected void Submit_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["HotConnectionString"].ConnectionString);
con.Open();
string cmdStr = "Select INST_ID, accessLevel, EmailAddress from Table1 where EmailAddress='" + TextBoxEA.Text + "'";
string cmdStr2 = "Select INST_ID, accessLevel, EmailAddress from Table2 where EmailAddress='" + TextBoxEA.Text + "'";
string insCmd = "Insert into Tablepass (EmailAddress, Password, INST_ID, accessLevel) values (@EmailAddress, @Password, @INST_ID, @accessLevel)";
string insCmd2 = "Insert into Tablepass (EmailAddress, Password, INST_ID, accessLevel) values (@EmailAddress, @Password, @INST_ID, @accessLevel)";
SqlCommand insertUser = new SqlCommand(insCmd, con);
SqlCommand insertUser2 = new SqlCommand(insCmd2, con);
insertUser.Parameters.AddWithValue("@EmailAddress", TextBoxEA.Text);
insertUser.Parameters.AddWithValue("@Password", TextBoxPW.Text);
insertUser.Parameters.AddWithValue("@INST_ID", TextBoxINST_ID.Text);
insertUser.Parameters.AddWithValue("@accessLevel", TextBoxaccessLevel.Text);
insertUser2.Parameters.AddWithValue("@EmailAddress", TextBoxEA.Text);
insertUser2.Parameters.AddWithValue("@Password", TextBoxPW.Text);
insertUser2.Parameters.AddWithValue("@INST_ID", TextBoxINST_ID.Text);
insertUser2.Parameters.AddWithValue("@accessLevel", TextBoxaccessLevel.Text);
try
{
insertUser.ExecuteScalar();
con.Close();
Response.Redirect("Login.aspx");
}
catch (Exception er)
{
}
}
protected void TextBoxEA_TextChanged(object sender, EventArgs e)
{
using (SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["HotConnectionString"].ConnectionString))
{
con.Open();
SqlCommand scmd = new SqlCommand("Select INST_ID, EmailAddress, accessLevel from Table1 where EmailAddress = @TextBoxEA", con);
SqlCommand scmd2 = new SqlCommand("Select INST_ID, EmailAddress, accessLevel from Table2 where EmailAddress = @TextBoxEA", con);
scmd.Parameters.Add(new SqlParameter("@TextBoxEA", TextBoxEA.Text));
scmd2.Parameters.Add(new SqlParameter("@TextBoxEA", TextBoxEA.Text));
TextBoxINST_ID.Text = string.Empty;
TextBoxaccessLevel.Text = string.Empty;
using (SqlDataReader dr = scmd.ExecuteReader())
{
while (dr.Read())
{
TextBoxINST_ID.Text = dr["INST_ID"].ToString();
TextBoxaccessLevel.Text = dr["accessLevel"].ToString();
}
}
using (SqlDataReader dr2 = scmd2.ExecuteReader())
{
while (dr2.Read())
{
TextBoxINST_ID.Text = dr2["INST_ID"].ToString();
TextBoxaccessLevel.Text = dr2["accessLevel"].ToString();
}
}