0

I am working with a MySQL sign up/registration system. If the user and pass are correct and has permission 0, he will log in as guest; if the user and pass are correct and user has permission 1, he will log in as administrator. If the user is guest, I want to open Form1, if he is admin, I will open Form 2. At this point my program reads / writes to the MySQL DB. How can I read a specific value (permission) and write conditionals depending on the result?

Auth :

        private bool validate_login(string user, string pass)
    {
        db_connection();
        MySqlCommand cmd = new MySqlCommand();
        cmd.CommandText = "Select * from miembros where usuario=@user and contraseña=@pass";
        cmd.Parameters.AddWithValue("@user", textBox1.Text);
        cmd.Parameters.AddWithValue("@pass", textBox2.Text);
        cmd.Connection = connect;
        MySqlDataReader login = cmd.ExecuteReader();
        if (login.Read())
        {

            connect.Close();
            return true;
        }
        else
        {
            connect.Close();
            return false;
        }
    }

1 Answer 1

1

Just access the data reader

if (login.Read())
        {
            x = login["FieldName"];
            connect.Close();
            return true;
        }
        else
        {
            connect.Close();
            return false;
        }    

a general advice to you when you are going to use MySQL with C#, it's better to use a framework like NHibernate that will help you with data access and date formats and many other things.

Sign up to request clarification or add additional context in comments.

2 Comments

Where x is a string, int or bool?
x is an object and you can cast the result or you can use login.GetInt32(0); if you are want to retrieve integervalue

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.