0

hi can anyone help me with this code that ive created for a login form, im having trouble with the username and password, ive highlighted the part that's giving me a problem.
Error Message: The name 'inputName' does not exist in the current context
: The name 'inputPass' does not exist in the current context

CODE:

namespace Jackson
{
    public partial class login : Form
    {
        Client mainWindow = new Client();


        public login()
        {
            InitializeComponent();
        }
        private void loginBindingNavigatorSaveItem_Click(object sender, EventArgs e)
        {
            this.Validate();
            this.loginBindingSource.EndEdit();
            this.loginTableAdapter.Update(this.dataSet.Login);

        }
        private void Form1_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'dataSet.Login' table. You can move, or remove it, as needed.
            this.loginTableAdapter.Fill(this.dataSet.Login);

        }

        private void loginBtn_Click(object sender, EventArgs e)
        {
            OleDbConnection conn = new OleDbConnection(@"provider = Microsoft.Jet.OLEDB.4.0;Data Source= C:\Documents and Settings\Developers ITD\My Documents\Visual Studio 2005\Projects\Jackson\Jackson\call.mdb");
            OleDbCommand com = new OleDbCommand("SELECT username, password FROM Login");
            OleDbDataReader reader;

            bool permit = false;

            try
            {
                conn.Open();
                reader = com.ExecuteReader();

                while (reader.Read())
                {
                    if ([U]inputName[/U] == (reader["usernameTextBox"].ToString()) && [U]InputPass[/U] == reader["passwordTextBox"].ToString())
                    {
                        permit = true;
                        break;
                    }
                }
                conn.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            if (permit == true)
                MessageBox.Show("Access granted");
            else
                MessageBox.Show("Access denied");

                Client Main = new Client();
                Main.Show();
                this.Hide();

Edited by __avd: Added [code] tags. For easy readability, always wrap programming code within posts in [code] (code blocks).

3
Contributors
3
Replies
7
Views
7 Years
Discussion Span
Last Post by SharpJohnnyG
0

I would suggest to use SELECT with WHERE clause.

private void loginBtn_Click(object sender, EventArgs e)
 {
      OleDbConnection conn = new OleDbConnection(@"provider = Microsoft.Jet.OLEDB.4.0;Data Source= C:\Documents and Settings\Developers ITD\My Documents\Visual Studio 2005\Projects\Jackson\Jackson\call.mdb");

     OleDbCommand com = new OleDbCommand("SELECT username FROM Login WHERE username=@uname and password=@upass");

     com.Connection=conn;
     com.Parameters.AddWithValue("@uname",usernameTextBox.Text);
     com.Parameters.AddWithValue("@upass",passwordTextBox.Text);

     conn.Open();

     object result=com.ExecuteScalar();

     conn.Close();

     if(result!=null) {
         MessageBox.Show("Access granted");
     }
    else {
         MessageBox.Show("Access denied");
    }
 ....
}

Edited by __avd: n/a

0

Thanx a lot for the code, it doesnt have any errors

-1

You have not said what inputName and inputPass are? if they are the textboxes directly then you must use .text

if (inputName.Text == whateverYourMatchingAgainst

if it is not the textbox directly then you must qualify the string by saying

string inputName = TheTextbox.Text;

hi can anyone help me with this code that ive created for a login form, im having trouble with the username and password, ive highlighted the part that's giving me a problem.
Error Message: The name 'inputName' does not exist in the current context
: The name 'inputPass' does not exist in the current context

CODE:

namespace Jackson
{
    public partial class login : Form
    {
        Client mainWindow = new Client();


        public login()
        {
            InitializeComponent();
        }
        private void loginBindingNavigatorSaveItem_Click(object sender, EventArgs e)
        {
            this.Validate();
            this.loginBindingSource.EndEdit();
            this.loginTableAdapter.Update(this.dataSet.Login);

        }
        private void Form1_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'dataSet.Login' table. You can move, or remove it, as needed.
            this.loginTableAdapter.Fill(this.dataSet.Login);

        }

        private void loginBtn_Click(object sender, EventArgs e)
        {
            OleDbConnection conn = new OleDbConnection(@"provider = Microsoft.Jet.OLEDB.4.0;Data Source= C:\Documents and Settings\Developers ITD\My Documents\Visual Studio 2005\Projects\Jackson\Jackson\call.mdb");
            OleDbCommand com = new OleDbCommand("SELECT username, password FROM Login");
            OleDbDataReader reader;

            bool permit = false;

            try
            {
                conn.Open();
                reader = com.ExecuteReader();

                while (reader.Read())
                {
                    if ([U]inputName[/U] == (reader["usernameTextBox"].ToString()) && [U]InputPass[/U] == reader["passwordTextBox"].ToString())
                    {
                        permit = true;
                        break;
                    }
                }
                conn.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            if (permit == true)
                MessageBox.Show("Access granted");
            else
                MessageBox.Show("Access denied");

                Client Main = new Client();
                Main.Show();
                this.Hide();

Edited by SharpJohnnyG: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.