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”两次,但都看到了同一行
如您所见,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/