场景
Winform中连接Mysql8并查询表中数据进行显示:
Winform中连接Mysql8并查询表中数据进行显示_BADAO_LIUMANG_QIZHI的博客-CSDN博客
在上面实现连接Mysql8的基础上,怎样获取数据库中所有的表名。
注:
博客:
https://blog.csdn.net/badao_liumang_qizhi
关注公众号
霸道的程序猿
获取编程相关电子书、教程推送与免费下载。
实现
在获取所有表名的点击事件中
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>();