0

I have two DataTables dt1 and dt2. Each table have different data in them but they have a common column ReportID.

Is there a way of joining the datatables similar to a SQL Inner Join?

I have tried using DataRelation but it didn't work

Thanks

1
  • 1
    why did the data relation not work. post some code and the issue you faced. Commented Mar 4, 2011 at 12:32

1 Answer 1

1

You could load your data tables into a DataSet and then you are free to create relations and query the data.

http://msdn.microsoft.com/en-us/library/ss7fbaez.aspx

Hope this helps

Sign up to request clarification or add additional context in comments.

3 Comments

thanks for that i did look at Datasets but it was creating a hierachical set i managed to use Linq for it but am now facing an issue of converting my result set into a DataTable to bind to my gridview source var results = from r in dtReports.AsEnumerable() join c in dtReportDetail.AsEnumerable() on r.Field<int>("ReportID") equals c.Field<int>("ReportID") select new List<object>(r.ItemArray).Concat(c.ItemArray); DataTable dtCombineTables = results.CopyToDataTable<DataTable>(); the CopyToDataTable method doesn't get recognised
Simple as that: // load into new DataTable DataTable dtCombineTables = result.CopyToDataTable();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.