gpt4 book ai didi

c# - MySQL数据读取器不读取

转载 作者:行者123 更新时间:2023-12-01 00:20:02 25 4
gpt4 key购买 nike

我试图从数据库中获取我的数据并显示在消息框中,但它不起作用。我试图在我的 while 循环中放置一个虚拟消息框,但似乎代码也没有进入它。有什么方法可以做到这一点吗?

这是我的代码:

 ConnectToDatabase();

MySqlCommand cmd = new MySqlCommand("Select Name, LPN From visitors Where password = '@password';", conn);
cmd.Parameters.AddWithValue("@password", decodeStr);

MySqlDataReader reader = cmd.ExecuteReader();

while (reader.Read())
{
MessageBox.Show("he");

name = reader["Name"].ToString();
lpn = reader["LPN"].ToString();
}

最佳答案

您需要删除 '@password' 部分中的单引号。使用单引号,数据库管理器认为这是一个 string literal ,不是参数。

这就是为什么您的阅读器没有任何数据的原因,因为您的密码列可能没有任何字符串作为@password

还有一些事情;

关于c# - MySQL数据读取器不读取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32050251/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com