Ok. After reading and testing and reading the comments here and testing. I have it working. The only problem is that when I enter a different email address and I click or tab into the next textbox, nothing changes. Why is that? Here is my code:
using System;
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;
using System.Web.Security;
using System.Security.Cryptography;
public partial class SubmitPage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["PasswordConnectionString"].ConnectionString);
con.Open();
string cmdStr = "Select count(*) from TableSecurity where EmailAddress='" + TextBoxEA.Text + "'";
SqlCommand userExist = new SqlCommand(cmdStr, con);
SqlCommand cmd = new SqlCommand("select INST_ID, EmailAddress from TableSecurity", con);
int temp = Convert.ToInt32(userExist.ExecuteScalar().ToString());
if (temp == 1)
{
lblMessage.Text = "User Name Already Exist!!!";
}
}
}
protected void Submit_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["PasswordConnectionString"].ConnectionString);
con.Open();
string cmdStr = "Select INST_ID, accessLevel, EmailAddress from TableCEO where EmailAddress='" + TextBoxEA.Text + "'";
string cmdStr2 = "Select INST_ID, accessLevel, EmailAddress from TableIALO where EmailAddress='" + TextBoxEA.Text + "'";
string insCmd = "Insert into TableSecurity (EmailAddress, Password, INST_ID, accessLevel) values (@EmailAddress, @Password, @INST_ID, @accessLevel)";
string insCmd2 = "Insert into TableSecurity (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);
try
{
insertUser.ExecuteNonQuery();
con.Close();
Response.Redirect("Login.aspx");
}
catch (Exception er)
{
lblMessage.Text = "User Already Exist";
}
finally
{
}
}
protected void TextBoxEA_TextChanged(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["PasswordConnectionString"].ConnectionString);
con.Open();
SqlConnection con2 = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["PasswordConnectionString"].ConnectionString);
con2.Open();
SqlCommand scmd = new SqlCommand("Select INST_ID, EmailAddress, accessLevel from TableCEO where EmailAddress = '" + TextBoxEA.Text + "'", con);
SqlCommand scmd2 = new SqlCommand("Select INST_ID, EmailAddress, accessLevel from TableIALO where EmailAddress = '" + TextBoxEA.Text + "'", con2);
SqlDataReader dr = scmd.ExecuteReader();
if (dr.Read())
{
TextBoxINST_ID.Text = dr["INST_ID"].ToString();
TextBoxaccessLevel.Text = dr["accessLevel"].ToString();
}
dr.Close();
con.Close();
con2.Close();
}
}