Getting the first record from a
DataTable
is not a hard thing to do. Simply access row 0 only. That would look something like this:
var row = DataSet.DataTables[0].Rows[0];
That will give you a
DataRow
that contains the first record from the first table in the
DataSet
. You could do this for each of your four tables. Then you could create a new
DataTable
and insert these four rows into it. The key here though would be that the four rows would have to have matching column names and types. Here is how you would manually create a
DataTable
:
http://www.dotnetperls.com/datatable[
^]
The bigger question I see here though is why are you do it this way? It seems like you could at least limit your query to only give you the first row in each table (
SELECT TOP 1 * FROM table
). You might also be able to do the joining of the four entries at the database level as well. Something like this:
SELECT TOP 1 FieldA, FieldB FROM table1
UNION ALL
SELECT TOP 1 FieldA, FieldB FROM table2
UNION ALL
SELECT TOP 1 FieldA, FieldB FROM table3
UNION ALL
SELECT TOP 1 FieldA, FieldB FROM table4
That would give you the top record from each table and join them together. The output would be four rows.
Obviously these last suggestions would be dependent on how your environment is set up, but if possible I would definitely recommend going this way.