I have two Tables in one database. I have a form that works like this. The user can put in an email address and password then confirm password then click the submit button and be redirected back to the login screen. The code I have is not working. I am selecting the right fields from the table and inserting them into a new table. Why is this not working? Table1 has the data already in it. Table2 is where I want to save the data to. So, if Table1 has INST_ID, Firstname, LastName, Emailaddress, Phone Number. I am selecting the INST_ID and Emailaddress from Table1 and inserting it into Table2 with the password. It will not insert into Table2, Why?
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 INST_ID, EmailAddress from TableSecurity where EmailAddress='" + TextBoxEA.Text + "'";
string cmdStr2 = "Select INST_ID, EmailAddress from TableCEO where EmailAddress ='" + TextBoxEA.Text + "'";
string cmdStr3 = "Select INST_ID, EmailAddress from TableIALO where EmailAddress ='" + TextBoxEA.Text + "'";
SqlCommand userExist = new SqlCommand(cmdStr, con);
SqlCommand cmd = new SqlCommand("select INST_ID, EmailAddress from TableSecurity", con);
SqlCommand cmd2 = new SqlCommand("select INST_ID, EmailAddress from TableCEO", con);
SqlCommand cmd3 = new SqlCommand("select INST_ID, EmailAddress from TableIALO", con);
int temp = Convert.ToInt32(userExist.ExecuteScalar().ToString());
if (temp == 0)
lblMessage.Text = "User Name Already Exist!!!<br /> Please Choose Another User Name.";
}
}
protected void Submit_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["PasswordConnectionString"].ConnectionString);
con.Open();
string chkUser = "select INST_ID, EmailAddress from TableCEO where EmailAddress'" + TextBoxEA.Text + "";
chkUser = "select INST_ID, EmailAddress from TableIALO where EmailAddress'" + TextBoxPW.Text + "";
SqlCommand chkUsercmd = new SqlCommand(chkUser, con);
string insCmd = "Insert into TableSecurity (INST_ID, EmailAddress, Password) values (@INST_ID, @EmailAddress, @Password)";
SqlCommand insertUser = new SqlCommand(insCmd, con);
insertUser.Parameters.AddWithValue("@EmailAddress", TextBoxEA.Text);
insertUser.Parameters.AddWithValue("@Password", TextBoxPW.Text);
insertUser.Parameters.AddWithValue("@INST_ID", TextBoxINST_ID.Text);
try
{
insertUser.ExecuteNonQuery();
con.Close();
Response.Redirect("Login.aspx");
}
catch (Exception er)
{
Response.Write("An error occurred: " + er.Message);
}
finally
{
}
}
}