C#代码:
try
{
string mydbConnection = "datasource=localhost;port=3306;username=root;password=Greenford123;";
MySqlConnection connDB = new MySqlConnection(mydbConnection);
MySqlCommand cmdDataBase = new MySqlCommand("SELECT * FROM project.student", connDB);
MySqlDataReader DBReader;
connDB.Open();
DBReader = cmdDataBase.ExecuteReader();
while (DBReader.Read())
{
List<string> mylist = new List<string>();
mylist.Add(DBReader.ToString());
foreach (var item in mylist)
{
MessageBox.Show("The details are " + item);
}
}
connDB.Close();
}
catch(Exception ex)
{
MessageBox.Show("Error! " + ex);
}
客观的:
我想在我的代码中实现的是:
-将数据库中的内容存储到列表中,然后输出列表。
然而,这是我得到的输出:
OUTPUT = "详细信息是 MySQL.Data.MySqlClient.MySqlDataReader"