gpt4 book ai didi

c# - MySQLDataReader 未将任何数据加载到所示表单上的指定位置

转载 作者:行者123 更新时间:2023-11-30 00:56:13 26 4
gpt4 key购买 nike

我在将信息从数据库加载到标签和图片框中时遇到问题。我认为我的代码可以正确执行我想要的操作,但我猜不是,因为它不起作用。下面是我正在使用的代码。对于数据库中的图片列,我存储图片的路径,而不是实际的 blob。如果您需要更多相关信息,请询问。

代码:

private void AirSpace_Shown(object sender, EventArgs e)
{
string connectionString = "datasource=localhost;port=3306;username=Admin;password=August211989";
Login login = new Login();
using (MySqlConnection conn = new MySqlConnection(connectionString))
{
using (MySqlCommand cmd = conn.CreateCommand())
{
string select = "SELECT username, email, premium, picture FROM userinfo.users WHERE username = @username;";
// (1) (2) (3) (4)
conn.Open();
cmd.CommandText = select;
cmd.Parameters.AddWithValue("@username", login.UsernameTextBox.Text);
using (MySqlDataReader Reader = cmd.ExecuteReader())
{

while (Reader.Read())
{
//Set the user's profile picture to the user's profile picture.
ProfilePicture.Load(Reader.GetString(4));
//Set the username to the user's username
Username.Text = Reader.GetString(1);
//Set the app version to the user's version
if (Reader.GetString(3) == "1")
{
AppVersionLabel.Text = "Premium";
}
else
{
AppVersionLabel.Text = "Free";
}
}
}
}
}

最佳答案

你可以试试这个。这看起来也是一个登录代码,所以我会添加逻辑,如果你循环超过一个,它会抛出一个错误,因为应该只有 1 个结果。

While(Reader.Read()){
//Set the user's profile picture to the user's profile picture.
string UserProfilePictureLocation = Reader.GetString(3);
ProfilePicture.Load(UserProfilePictureLocation);
//Set the username to the user's username
Username.Text = Reader.GetString(0);
//Set the app version to the user's version
if (Reader.GetString(2) == "1")
{
AppVersionLabel.Text = "Premium";
}
else
{
AppVersionLabel.Text = "Free";
}
}

关于c# - MySQLDataReader 未将任何数据加载到所示表单上的指定位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20526227/

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