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();

Recommended Answers

All 3 Replies

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");
    }
 ....
}

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

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();
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.