0

I often use the DataTable class in my .NET WCF services, since many of our SPs require TVPs. As far as I know, DataTables are the only way of passing TVPs to SPs.

It just occurred to me that similarly to how tables, in which information is stored according to rows and columns are useful, that the DataTable class may be useful beyond just as a means of interfacing with SQL Server TVPs.

Actually... thinking about this, I have previously written code that iterated over a DataTable's rows, building up an HTML string. However the main reason we used a DataTable as because the same table could be passed to SQL Server as a TVP.

Looking at the docs: https://msdn.microsoft.com/en-us/library/system.data.datatable%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396, it looks like you can effectively create relational object models using DataTables.

Would using DataTables be an effective way of caching data retrieved from a SQL Server in a service?

Another potential use-case that comes to mind... Would there be any benefit of using a DataTable for a collection instead of List<MyType>?

Zach Smith
  • 8,458
  • 13
  • 59
  • 133

1 Answers1

1

Datatables are slower than Lists/Enumerables, and its better to use dataAdapter while reading data if you really care about performance.

But Datatables can be really useful as a item source for grids, where you want to just publish whole table data on the UI and no need to specify each column individually as in the case of List.

Gaurav Jalan
  • 467
  • 2
  • 14