我有一个这样的示例表格:
我dbconnect
用 select 方法创建了类,它是这样的:
public List<string>[] Select(string username, string password)
{
string query = "SELECT * FROM ms_user where username = '" + username +
"' and password = '" + password + "'";
//Create a list to store the result
List<string>[] list = new List<string>[2];
list[0] = new List<string>();
list[1] = new List<string>();
//Open connection
if (this.OpenConnection() == true)
{
//Create Command
MySqlCommand cmd = new MySqlCommand(query, connection);
//Create a data reader and Execute the command
MySqlDataReader dataReader = cmd.ExecuteReader();
//Read the data and store them in the list
while (dataReader.Read())
{
list[0].Add(dataReader["username"] + "");
list[1].Add(dataReader["password"] + "");
}
//close Data Reader
dataReader.Close();
//close Connection
this.CloseConnection();
//return list to be displayed
return list;
}
else
{
return list;
}
}
如何使用此方法登录?因为该方法返回一个列表而不是true
检查false
数据库中是否存在该值。