这是我第一次使用DataSets和BindingSources,所以请对我温柔。作为一个更复杂的报告系统的一部分(我已经将它蒸馏成一个基本的化身,但它仍然不会正确运行),我试图从数据库使用DataSet拉数据有问题(即是不是通过设计师设置的)。这里是我到目前为止的代码:我这个基础上我的了.Designer.cs文件看到设置通过设计师结合后的代码使用BindingSource将DataSet链接到DataGridView,但没有数据
// pull the data set
var dsReportData = new Reports2.ReportTest2();
dsReportData.BeginInit();
dsReportData.SchemaSerializationMode = SchemaSerializationMode.IncludeSchema;
// bind tha data set
BindingSource bsReportBinding = new BindingSource();
((ISupportInitialize)bsReportBinding).BeginInit();
bsReportBinding.DataMember = dsReportData.Tables[0].TableName;
bsReportBinding.DataSource = dsReportData;
bsReportBinding.ResetBindings(true);
// test this stuff
dgvTester.DataSource = bsReportBinding;
dsReportData.EndInit();
((ISupportInitialize)bsReportBinding).EndInit();
。 dgvTester只是一个DataGridView,其中包含在设计器中创建的默认属性。
ReportTest2数据集只有一个TableAdapter,通过设计器添加。如果我去VS中的数据 - >预览数据并预览了3210对象,它就会返回数据,就像我运行用于在SQL Server Management Studio中创建TableAdapter的查询一样。
但是,运行实际的代码会导致DataGridView从查询结果中获取列名称,而不是实际的数据。调试器显示dsReportData.payments.Rows.Count == 0
(并且,是的,dsReportData.Tables [0]是付款)。
我最终打算使用BindingSource向ReportViewer提供数据,但首先要确保在去调试报表之前检索数据没有问题。
希望我错过了这里明显的东西。我希望如此...