【问题标题】:Display SQL Server table in DataGridView在 DataGridView 中显示 SQL Server 表
【发布时间】:2009-12-05 22:16:14
【问题描述】:

我认为这是一个菜鸟问题,但我是 .NET 中的 SQL Server 的新手,我已经为此浪费了几个小时......

我开始了新项目,在空表单上插入了 DataGridView,我选择了 Add->Database 作为数据源,并创建了新的 SQL Server 数据库文件。我称它为 db.mdf。现在我得到名为 dbDataset 的 DataSet 和名为 dbDataSetBindingSource 的 BindingSource。我还将 LINQ to SQL 类添加到我的项目中,并将我的表(我之前在其中添加了一些行)拖到我的 .dbml 中。接下来我双击我的 dbDataset 并在设计器中拖放同一个表。

我希望你现在有一张图片;)。问题是当我运行程序时,DataGridView 中没有显示任何内容。我知道我能做到

dbDataClassesDataContext db = new dbDataClassesDataContext();
var records= from rec in db.MyTable select rec;
dataGridView1.DataSource = records;

而且效果很好。但我相信 dbDataSet 和 dbDataSetBindingSource 也应该可以工作......如何使用它们只是在 DataGridView 中显示数据?

【问题讨论】:

    标签: c# sql linq datagridview


    【解决方案1】:

    我的天啊,找到了...对于将来遇到此问题的任何其他人。在设计器中单击 BindingSource,然后在属性中选择 DataMember 中的表。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-28
      • 2013-12-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多