1

enter image description here

I've these two tables, I want to generate a crystal report in which I've a sub report listing all the orders by store. But I'm having problem setting data source of sub report.

ReportsDataSetTableAdapters.StoreTableAdapter adp = new ReportsDataSetTableAdapters.StoreTableAdapter();
MainOrderReport report = new MainOrderReport();
ReportsDataSetTableAdapters.OrderTableAdapter del = new ReportsDataSetTableAdapters.OrderTableAdapter();
report.Subreports[0].SetDataSource(del.GetData().DefaultView);
report.SetDataSource(adp.GetData().DefaultView);
crystalReportViewer.ReportSource = report;
crystalReportViewer.Refresh();

But this code is throwing this exception: "Failed to enable constraints. One or more rows contain values violating non-null, unique or foreign-key constraints". Kindly help me, what I'm missing here.

Desire
  • 107
  • 1
  • 2
  • 16

2 Answers2

0

Try clearing the connection first:

report.Subreports[0].DataSourceConnections.Clear();
report.Subreports[0].SetDataSource(adp.GetData().DefaultView);
crystalReportViewer1.ReportSource = report;
crystalReportViewer1.Refresh();
Paul Zahra
  • 9,522
  • 8
  • 54
  • 76
  • I'm still getting this exception, " Failed to enable constraints. One or more rows contain values violating non-null, unique or foreign-key constraints – Desire Jun 02 '14 at 08:13
  • @Desire Okidoke, then follow the answer on this SO post to investigate your error a bit more... http://stackoverflow.com/questions/7026566/failed-to-enable-constraints-one-or-more-rows-contain-values-violating-non-null – Paul Zahra Jun 02 '14 at 08:35
0

As per your given DataSet image, your OrderDataTable is child of StoreDataTable. While in your code you are filling your child first and parent later. And in your DataSet you have defined a constraint between the two tables.

Probably this is the reason why you are getting this error. Try filling the parent Table first, then child Table.

sallushan
  • 1,134
  • 8
  • 16