我有一些问题,我在互联网上看到了和平的代码,只有这与Oledb
.
现在我重写了 MySQL.data.mysqlclient 的代码,如下所示:
MySqlDataReader dr = null;
MySqlCommand cmd = null;
string cmdstr = "SELECT * FROM users WHERE email='"+UsrName.Text+"' and password='"+PassWrd.Text+"' LIMIT 1";
dr = cmd.ExecuteNonReader();
cmd = new MySqlCommand(cmdstr, connection);
cmd.Dispose();
if (dr.Read() == true)
{
MessageBox.Show("Succesvol ingelogd");
}
else
{
MessageBox.Show("Geen juiste gegevens");
}
connection.Close();
}
现在的问题是另一种方法dr = cmd.ExecuteNonReader()
。
更新 - - - - - - - -
string server;
string database;
string uid;
string password;
server = "localhost";
database = "cmstt";
uid = "root";
password = "";
string connectionString;
connectionString = "SERVER=" + server + ";" + "DATABASE=" +
database + ";" + "UID=" + uid + ";" + "PASSWORD=" + password + ";";
MySqlConnection connection = new MySqlConnection(connectionString);
connection.Open();
MySqlDataReader dr = null;
MySqlCommand cmd = null;
string cmdstr = "SELECT * FROM users WHERE email='"+UsrName.Text+"' and pass='"+PassWrd.Text+"' LIMIT 1";
dr = cmd.ExecuteReader();
cmd = new MySqlCommand(cmdstr, connection);
if (dr.Read() == true)
{
MessageBox.Show("Succesvol ingelogd");
}
else
{
MessageBox.Show("Geen juiste gegevens");
}
cmd.Dispose();
connection.Close();