Here is the problem:
For example if I enter in “A” as the user name and “A” as the password, then click add user nothing happens. But if I go back in and now type “B” for the user name and “B” for that password and click add user it adds the previous entry “A” & “A” into the table. Like it’s one behind?
I know I have something out of place.
public partial class frmManageUsers : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnAddUser_Click1(object sender, EventArgs e)
{
//string userName, userPassword;
if (txtUserName.Text == "" || txtUserName.Text == null)
{
lblError.Text = ("User Name may not be empty");
lblError.ForeColor = System.Drawing.Color.Red;
return;
}
// else
// userName = (txtUserName.Text);
if (txtPassword.Text == "" || txtPassword.Text == null)
{
lblError.Text = ("Password may not be empty");
lblError.ForeColor = System.Drawing.Color.Red;
return;
}
//else
// userPassword = (txtPassword.Text);
//using (OleDbConnection conn = new OleDbConnection("PayrollSystem_DBConnectionString"))
OleDbConnection conn =
new OleDbConnection(ConfigurationManager.ConnectionStrings["PayrollSystem_DBConnectionString"].ConnectionString);
{
string insert = "Insert INTO tblUserLogin (UserName, UserPassword, SecurityLevel) Values (@UserName, @UserPassword, @SecurityLevel)";
OleDbCommand cmd = new OleDbCommand(insert, conn);
cmd.Parameters.Add("@UserName", txtUserName.Text);
cmd.Parameters.Add("@UserPassword", txtPassword.Text);
cmd.Parameters.Add("@SecurityLevel", drpdwnlstSecurityLevel.SelectedValue);
conn.Open();
cmd.ExecuteNonQuery();
}
Session["UserName"] = txtUserName.Text;
Session["Password"] = txtPassword.Text;
Session["SecurityLevel"] = drpdwnlstSecurityLevel.SelectedValue;
Server.Transfer("frmManageUsers.aspx");
//Server.Transfer("grdUserLogin");
}
protected void drpdwnlstSecurityLevel_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
Your code seems to be missing a conn.Close(). That would cause the delay in writing to the table. Also, consider putting your conn in a using statement to properly dispose of the object.