场景
Winform中连接Mysql8并查询表中数据进行显示:
Winform中连接Mysql8并查询表中数据进行显示_BADAO_LIUMANG_QIZHI的博客-博客
在上面实现连接Mysql8的基础上,怎样获取数据库中所有的表名。
注:
实现
在获取所有表名的点击事件中
DataGridViewColumn checkCol = new DataGridViewCheckBoxColumn();
checkCol.Name = "选择";
this.dataGridView_show_tables_name.Columns.Add(checkCol);
DataTable tbName = mySqlConnection.GetSchema("Tables");
if (tbName.Columns.Contains("TABLE_NAME"))
{
foreach (DataRow dr in tbName.Rows)
{
tableNameList.Add((string)dr["TABLE_NAME"]);
}
}
this.dataGridView_show_tables_name.DataSource = this.tableNameList.Select(x => new { Value = x }).ToList();
其中
List<string> tableNameList = new List<string>();