MySql数据读取器不检索该行

时间:2017-12-06 16:16:34

标签: c# mysql

我正在使用MySQL数据库制作Xamarin应用程序。我希望从我的表leerlinggebruikersnaam中获取值leerlingwachtwoordleerlinglogin但是当我填写正确的usernamepassword时,它仍会转到else语句inlog invalid这里是我在Visual Studio中使用的代码:

void LoginKlik(object sender, EventArgs e)
        {
            MySqlConnection con = new MySqlConnection("Server=arabig.nl;Port=3306;database=arabignl_project;User Id=arabignl_project;Password=**password**;charset=utf8");
            try
            {
                con.Open();

                MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand("SELECT leerlinggebruikersnaam, leerlingwachtwoord FROM arabignl_project.myfirstmodule$leerlinglogin WHERE(leerlinggebruikersnaam  = @gebruiker AND leerlingwachtwoord = @wachtwoord)", con);
                cmd.Parameters.AddWithValue("@gebruiker", LeerlingGebruikersnaam);
                cmd.Parameters.AddWithValue("@wachtwoord", LeerlingWachtwoord);

                MySqlDataReader reader = cmd.ExecuteReader();

                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        LoginLog.Text = "Inloggen gelukt";
                    }
                }
                else
                {
                    LoginLog.Text = "Inloggen mislukt";
                }
                reader.Close();
            }
            catch (MySqlException ex)
            {
                LoginLog.Text = ex.ToString();
            }
            finally
            {
                con.Close();
            }
        }

这是数据库专栏:

Database

0 个答案:

没有答案