【发布时间】:2020-03-25 19:09:33
【问题描述】:
我想在一个组合框中显示 MySQL 数据库的所有表名,并在另一个组合框中显示从第一个组合框中选择的表的行。
string cmdstr = "select * from sys.tables";
string conStr = @"Data Source=DESKTOP-63RVRDI\IBRAHIMDATABASE;Initial Catalog=Sample_DataBase;Integrated Security=True"
DataTable dt = new DataTable();
SqlDataAdapter sda = new SqlDataAdapter(cmdstr,conStr);
try
{
sda.Fill(dt);
foreach (DataTables tbl in dt.DataTables)
{
comboBox1.Items.Add(tbl[1]);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
【问题讨论】:
-
感谢您的贡献。请更具体地提出您的问题。你没有提到你的问题到底是什么。
-
SqlDataAdapter适用于 Microsoft SQL Server 数据库 - 不是 MySQL .....所以您使用的是 MySQL,还是(MS)SQL Server?请更新您的问题并为您的问题添加适当的数据库标签
标签: c#