本文共 954 字,大约阅读时间需要 3 分钟。
static void Main(string[] args) { Console.WriteLine(user("k", "1")); Console.WriteLine(user("天下", "000")); Console.ReadKey(); } static bool user(string username, string password) { string connectstr = "server=127.0.0.1;port=3306;database=mygame;user=root;password=1234"; MySqlConnection connection = new MySqlConnection(connectstr); connection.Open(); try { string str = "select *from users where username=@kk and password=@pp"; MySqlCommand command = new MySqlCommand(str, connection); command.Parameters.AddWithValue("kk", username); command.Parameters.AddWithValue("pp", password); MySqlDataReader reader = command.ExecuteReader(); if (reader.Read()) { return true; } } catch (Exception e) { Console.WriteLine(e); } return false; }
转载地址:http://obrxo.baihongyu.com/