【问题标题】:Using Imported DataSet to fill DataGridView使用 Imported DataSet 填充 DataGridView
【发布时间】:2019-07-19 10:23:11
【问题描述】:

在我的 WindowForm 项目中,我使用添加新数据源向导导入了我的 SQL Server 数据库。因此,在我的项目中,我的数据库中的每个表现在都有一个 DataSet 和一个 TableAdapter。

问题是如何使用这些导入的对象来填充我的datagridview?

在此处的示例 (https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.datagridview.datasource?view=netframework-4.8) 中,他们似乎正在创建一个新对象(不使用我导入的现有对象)。

我希望有人能指出我正确的方向。

【问题讨论】:

  • 您是否在设计器中打开了 DataGridView 的 DataSource 属性的 ComboBox 选择器?

标签: c# winforms datagridview datasource


【解决方案1】:

这是什么意思?抱歉使用 MySQL 但它类似于 SQL

string conn = "datasource=localhost;port=3306;username=root;password=;CharSet=utf8mb4;";
                string query = "SELECT * FROM project1.workers";


                connection = new MySqlConnection(conn);
                adapter = new MySqlDataAdapter(query, connection);


                ds = new DataSet();
                adapter.Fill(ds, "workers");
                datagrdvPracownicy.DataSource = ds.Tables["workers"];

connection.Close();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-23
    相关资源
    最近更新 更多