.NET Questions (CLOSED)

Questions and Answers on any aspect of .NET. Now closed.

This discussion group is now closed.

Have a question about .NET development? Try stackoverflow.com, a worldwide community of great developers asking and answering questions 24 hours a day.

The archives of .NET Questions contain years of Q&A. Even older .NET Questions are still online, too.

ADO.NET 2.0 Master Detail Troubles

I'm trying to setup a master-/detail relationship and binding master to grid1 and detail to grid2.

If I select * from master and * from detail, fill the dataset and add a datarelation object to the dataset, everything works fine.

However, I don't want to "select * from master".
I'd like to 'select * from master where nMasterState=1'

Now I would like to only fetch those childrecords, that belong to the previously selected master.

Is it possible to setup something like that in .NET automatically?

In Delphi/Win32 the detail-SQL statement was set to something like:
select * from details where nMasterId=:nMasterId
Then the datasource of the detail was set to the Master-Source and everything was working fine.

I can't believe that this doesn't work in .NET 2.0.
Maybe I'm approaching this issue completely wrong ???

Thursday, July 20, 2006
I am doing a similar thing. This web site helped.

Keith Send private email
Thursday, July 20, 2006
You should be able to do this by setting the RowFilter property of the DataView that is bound to the grid.  See the MSDN docs for details.
BillT Send private email
Friday, July 21, 2006
If it seems like those queries arent' working, consider what order the DataTables are being filled in.  Even if it is all in one round trip, you'll want to fill the master DataTable first, or else the DataSet will complain about referential integrity when you try to add the first detail data row that has no parent.  Alternatively, you can tell the DataSet to temporarily stop enforcing such constraints.  You could say ds.EnforceConstraints = false right before filling the DataSet, and then ds.EnforceConstraints = true right after.  When you get the horribly nebulous exception about "some sort of constraint was violated, and I know exactly what one it was, but I won't tell you..." then it may come in handy to write a little tool that dumps the DataSet's current schema including constraints to a file, and take a good hard look at the result sets you're trying to put into that structure.  I've done a lot of multi-table dataset filling, and although the exception is not helpful, it's always thrown when I really was misusing it.
Notorious L
Friday, July 21, 2006
I filled the DataSet in the correct order.

But this way you can only select all data from the master and all data from the detail. Which would be a little hard on the server, if every master contains a lot of detail records.

I have the Chris Sells book, but I couldn't find a solution to this.

I guess I could just join those two tables and fill the dataset by hand. But I was hoping that there would be some automatic way to do this.
Fritz Send private email
Saturday, July 22, 2006
OK, thanks guys, it works.

I'm filling the master first and handle the "SelecedIndexChanged" event of the datagrid, where I set the paramater for the detail-data adapter accordingly and fill the detail dataset from there.
Fritz Send private email
Saturday, July 22, 2006

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
Powered by FogBugz