How to convert an IEnumerable to a DataTable in the same way as we use ToList or ToArray

LINQ provides us some extension methods to convert an IEnumerable to a collection e.g. ToList(), ToArray() etc. But what if you want to convert the enumerable to a DataTable. There is no built in extension method for that currently.                 var v = (from x in collection Select x).ToDataTable();   But if required we can…

4

How to force System.Xml.Xsl.XslCompiledTransform class to not use self closing tags for empty nodes

In .NET 2.0 framework when you use System.Xml.Xsl.XslCompiledTransform class for transforming a document then we always get self closing tags for all the elements which have nothing inside their body. There is no direct way to ask it to use separate closing tags e.g. <BODY> <TABLE></TABLE> <BR></BR> </BODY>   transforms as   <BODY> <TABLE/> <BR/>…

1

Hung condition on a query to SQLCLR stored procedure doing P/Invoke on a native dll

If you run into a scenario where you see your managed stored procedure from SQLCLR hung perpetually while calling a native dll method using P/Invoke, You may have to check following things. Run following query from another connection  select os.task_address, os.state, os.last_wait_type, clr.state, clr.forced_yield_count from sys.dm_os_workers os join sys.dm_clr_tasks clr on (os.task_address = clr.sos_task_address) where…

0

How to find out the data-reader referencing an ADO.NET connection object to fix the error: "There is already an open DataReader associated with this Command which must be closed first"

Sometimes while executing a DB command in ADO.NET we come across below error. There is already an open DataReader associated with this Command which must be closed first   This error is generated when we try to execute some query using a connection (with MARS disabled) which was earlier being used by some other component…

1