K
K
KurwaTM2021-09-21 22:12:17
MySQL
KurwaTM, 2021-09-21 22:12:17

Why doesn't MySql authorization work in C# and WPF?

Hello. I've been sitting for 5 hours and I don't understand why mysql authorization code doesn't work for me. I looked at the guides, nothing helped. So here is the code

using System;
using System.Windows;
using MySql.Data.MySqlClient;

namespace GoodWork
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow
    {
        public Manager _m;
        private MySqlConnection connection;
        public MainWindow()
        {
            InitializeComponent();
        }

        private void ExitClick(object sender, System.Windows.RoutedEventArgs e)
        {
            Close();
        }

        private void Submit(object sender, System.Windows.RoutedEventArgs e)
        {
            string loginL = Login.Text;
            string passwordD = Password.Text;
            string connStr = "server=localhost;user=mysql;database=users;password=mysql;";
            connection = new MySqlConnection(connStr);

            try
            {
                connection.Open();
                MySqlCommand cmd = new MySqlCommand("SELECT * FROM user WHERE login='" + loginL + "' AND password='" + passwordD + "'", connection);
                MySqlDataReader dr = cmd.ExecuteReader();
                if (dr.Read())
                {
                    _m.GetUser = loginL;
                    _m.GetPassword = passwordD;
                    MessageBox.Show("OK");
                }
                else
                {
                    MessageBox.Show("Eror " + loginL + " LLLL " + passwordD);
                }
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }


            connection.Close();
        }
    }
}


but the error itself
614a2e76ae41b997620762.png
Thanks for the answer!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question