C# UWP 查看两个数据库行

标签 c# mysql database uwp

string myConnectionString;
myConnectionString = "server=localhost;uid=root;pwd=root;database=medicloud;SslMode=None;charset=utf8";

MySqlConnection connection = new MySqlConnection(myConnectionString);
MySqlCommand cmd = new MySqlCommand();

cmd.CommandType = CommandType.Text;
string sqlStr = "Select arm from assign where userId=@name";
cmd.Parameters.AddWithValue("@name", txtValue.Text);

cmd.CommandText = sqlStr;
cmd.Connection = connection;

EncodingProvider ppp;
ppp = CodePagesEncodingProvider.Instance;
Encoding.RegisterProvider(ppp);

connection.Open();

MySqlDataReader reader = cmd.ExecuteReader();
reader.Read();
string databaseLine = (reader["arm"].ToString());
connection.Close();

#endregion
txtExercise.Text = databaseLine + " (Uncomplete)\n" + databaseLine;

我正在尝试查看数据库中的两行数据。但是,我不知道如何查看它。有人能帮我吗?我尝试输入“databaseLine”两次,但都看到了同一行

This is my database setup

如您所见,Rachel 有两种锻炼方式。我想在 txtExercise.Text 查看这两个练习。但是我只能看第一个,看不到第二个。

最佳答案

reader.Read() 将阅读器移动到下一行。您只调用一次,因此只读取第一行。

您可以在 while 循环中执行此操作。

MySqlDataReader reader = cmd.ExecuteReader();
while (reader.Read()) //reader.Read returns false when there are no more rows.
{
    string databaseLine = (reader["arm"].ToString()); //read the value of the current row
    txtExercise.Text += databaseLine + " (Uncomplete)\n"; //append the value to the output        
}

关于C# UWP 查看两个数据库行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51355743/

相关文章:

database - 使用带条件的计数函数在 Cognos Framework Manager 中创建计算量度

database - 使用 .NET 连接到远程服务器中的 Oracle

mysql - FATAL : role "root" does not exist, Rails 仅在网站上,Rails 控制台有效

c# - 可观察树 - 哪些事件会发生?

php - 如何使用 MySQL 制作 PHP/HTML 表单?

mysql - 给出用户的总订单价格,不重复

mysql - 从 MySQL 数据库的一个表中搜索一列并返回不同的列

c# - 使用 Open AI,我需要检查返回的字符串是否一遍又一遍地重复字符

c# - 来自网站的电子邮件未生成 html?

c# - HttpPostedFileBase 返回 null