-1

so, I have this code

    MySqlConnection connection = new MySqlConnection("Server=localhost;Port=3306; Database=brez-db;Uid=root;Pwd=root;");

        try {
            connection.Open();
            String Query = "SELECT 1 FROM users_table WHERE user_Username='" + usernameTB.Text + "' AND user_Password='" + passwordTB.Password + "'";
            MySqlCommand myCommand = new MySqlCommand(Query, connection);
            MySqlDataReader myReader = myCommand.ExecuteReader();

            while (myReader.Read())
            {
                String str = myReader.GetString("user_Username").ToString();
                MessageBox.Show(str);
            }


        }
        catch(Exception ex) { throw; }
        finally { }

but

while(myReader.Read()){} 

returns only 1 and 0 . 1 if there is a value inside and 0 if there's nothing.

I've tried many things to get the value but nothing, any suggestion? I'm writing a wpf C# app

PS: I know that its a good thing to use parameters for security, but I want to make a simple code for now

Gian Paolo
  • 4,161
  • 4
  • 16
  • 34

1 Answers1

0

Remove 1 after the select. Also you should use query for the name of your string,not Query,it looks like it is reserved for something. Also,you should get your string like this:

string sUsername= myReader["ColumnName"].ToString();

or like this

string sUsername= myReader[0].ToString();

And in the finally you are missing connection.Close();

Alexander
  • 405
  • 7
  • 17