0

我有一些问题,我在互联网上看到了和平的代码,只有这与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();
4

2 回答 2

2

不会ExecuteReader()ExecuteNonReader()

// 在此处提及您的连接和连接字符串。

        connection.open()

        SqlDataReader dr = null;
        MySqlCommand cmd = null;
        string cmdstr = "SELECT * FROM users WHERE email='"+UsrName.Text+"' and password='"+PassWrd.Text+"' LIMIT 1";

        cmd = new MySqlCommand(cmdstr, connection);
        dr = cmd.ExecuteReader();

        if (dr.Read() == true)
        {
            MessageBox.Show("Succesvol ingelogd");
        }
        else
        {
            MessageBox.Show("Geen juiste gegevens");
        }
        connection.Close();

    }
于 2012-12-09T17:27:39.377 回答
0

您正在过早地处理 cmd 。在关闭连接之前将其丢弃。

于 2012-12-09T17:26:41.743 回答