Есть такой код. В нём, по полученному мак адресу, надо спарсить с базы два значения UserName и Password. Помогите реализовать, а то тут ошибка вылазит. Скорее всего неправильный запрос я сделал public static void Log_in() { string macAdress = GetMacAdress(); Console.Write("Input your username: "); string Polusername = Console.ReadLine(); Console.Write("Input your password: "); string Polpassword = Console.ReadLine(); string connString = ConfigurationManager.AppSettings.Get("Db"); MySqlConnection connection = new MySqlConnection(connString); connection.Open(); string sravn = $"SELECT UserName FROM Название бд WHERE MacAdress LIKE {macAdress}"; string sravn2 = $"SELECT Password FROM Название бд WHERE MacAdress LIKE {macAdress}"; MySqlCommand command = new MySqlCommand(sravn, connection); MySqlDataReader reader = command.ExecuteReader(); MySqlCommand command2 = new MySqlCommand(sravn2, connection); MySqlDataReader reader2 = command.ExecuteReader(); string username = null; string password = null; while (reader.Read()) { username = reader["UserName"].ToString(); } while (reader2.Read()) { password = reader2["Password"].ToString(); } if (username == Polusername && password == Polpassword) { Console.WriteLine("entrance is allowed"); } else { Console.WriteLine("no entry allowed"); Log_in(); } } C# public static void Log_in() { string macAdress = GetMacAdress(); Console.Write("Input your username: "); string Polusername = Console.ReadLine(); Console.Write("Input your password: "); string Polpassword = Console.ReadLine(); string connString = ConfigurationManager.AppSettings.Get("Db"); MySqlConnection connection = new MySqlConnection(connString); connection.Open(); string sravn = $"SELECT UserName FROM Название бд WHERE MacAdress LIKE {macAdress}"; string sravn2 = $"SELECT Password FROM Название бд WHERE MacAdress LIKE {macAdress}"; MySqlCommand command = new MySqlCommand(sravn, connection); MySqlDataReader reader = command.ExecuteReader(); MySqlCommand command2 = new MySqlCommand(sravn2, connection); MySqlDataReader reader2 = command.ExecuteReader(); string username = null; string password = null; while (reader.Read()) { username = reader["UserName"].ToString(); } while (reader2.Read()) { password = reader2["Password"].ToString(); } if (username == Polusername && password == Polpassword) { Console.WriteLine("entrance is allowed"); } else { Console.WriteLine("no entry allowed"); Log_in(); } }
@aChanCode, вот я же и говорю, что запрос неправильно построен, прошу помочь посмтроить его правильно. Это выдаётся мой мак адрес, но его запрос подставляет, как столбец, а мне надо, чтобы по значению этого мак адреса вывелись UserName и Password, который находятся в одной строчке в базе с ним
кавычки вокруг мак адреса поставь (но это так - объяснение почему ошибка, вообще лучше используй параметры для передачи значений)
Minin_inactive4471240, https://dev.mysql.com/doc/connector-net/en/connector-net-tutorials-parameters.html