linq to sql - LINQ2SQL to DataTable -
What is the easiest way to copy a LINQ2 Adionet Datatebl SQL table?
Here's a blog post on an extension method which I think you want to do:
Code by Keith Elder
/// & lt; Summary & gt; /// It will take anything which implements the Icolung interface and /// converts it into a dataset. /// & lt; / Summary & gt; /// & lt; Example & gt; Data Set Converter from the /// collection = new archiveDataSet & lt; Letter [] & gt; (Letters); /// Dataset DS = Converter Creditsdata (); /// & lt; / Example & gt; /// & lt; Typename name = "t" & gt; & Lt; / Typermum & gt; Public category archiveDataDataset & lt; T & gt; Where t: system Compiler Election (T _collection; public Sngrhtoddetaset (T-List) {_collection = list;} private Snpttiinfo [] _propertyCollection = null; private Snpttiinfo [] property compilation {receive (if (_proprti collection == null) {_propertyCollection = GetPropertyCollection (); } return _proprti collection;}} private Snpttiinfo [] GetPropertyCollection () {if (_collection.Count & gt; 0) {IEnumerator enumerator = _collection.GetEnumerator (); enumerator.MoveNext (); return counter. current. GetType (). GetProperties ();} Return Null;} Create Public Dataset DataSet () {DataSet DS = No Or datasets ( "GridDataSet"); ds.Tables.Add (FillDataTable ()); return ds;} private Datatebl Fildetatebl () {Ainemetretr scorer = _collectionkGetEnumerator (); Datatabl dt = Bnaaadetatebl (); while (counter. Mukypustk ()) {dt.Rows.Add (FillDataRow (dt.NewRow (), calculator. current));} return dt;} private Detaro FillDataRow (Detaro Detaro, object P) Snpdainfo property {foreach (PropertyCollection) {dataRow [Property.Name.ToString ()] = property.GetValue (P, Blank); } Returns Detroit; } Create Personal DataTable DataTable () {Datatable DT = New Datatable ("Grid DataTable"); Foreach property in property property {dt.Column.Add (property.Name.ToString ()); } Return DT; }}
Comments
Post a Comment