Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Select to a temporary cursor
Message
From
04/12/2008 21:12:31
John Baird
Coatesville, Pennsylvania, United States
 
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01365559
Message ID:
01365571
Views:
12
>Hi.
>Is there a way in .net (C#) to select to a temporary Cursor and then use this as the source
> of another select e.g.
>
>Select * ,.....from Tablea Into Table Temp1
>Select * from Temp1 into Table Temp2
>Select * from Temp2 into table Temp3...etc
>
>The above selects are just examples
>Each select is more complicated , with numerous fields and some
> of the selects are done for grouping purposes.
>
>Any help appreciated.
>regards,
>Gerard


Hi Gerard,

I believe you can do what you want using LinQ to DataSets.

use LinQ to datasets to issue your select from datatable 1 into your var object.
convert var object to a datatable

each subsequent select and convert takes you back to another datatable.. until you reach the end of the chain.


Kevin Goff published some excellent code as an extension method to converst the anonymous type "var" result to a datatable for you.
// Take the anonymous type result "NewResult" and convert it to a DataTable

DataTable dtResults = NewResult.ToADOTable( rec => new object[] {NewResult});


public static class VarToTable
{
   public static DataTable ToADOTable<T>(
      this IEnumerable<T> varlist, CreateRowDelegate<T> fn)
   {
      DataTable dtReturn = new DataTable();
      // Could add a check to verify that there is an element 0
      T TopRec = varlist.ElementAt(0);

      // Use reflection to get property names, to create table
      // column names
      PropertyInfo[] oProps = ((Type)TopRec.GetType()).GetProperties();
      foreach (PropertyInfo pi in oProps)
         dtReturn.Columns.Add(pi.Name, pi.PropertyType);
      foreach (T rec in varlist)
      {
         DataRow dr = dtReturn.NewRow();
         foreach (PropertyInfo pi in oProps)
            dr[pi.Name] = pi.GetValue(rec, null);
         dtReturn.Rows.Add(dr);
      }
      return (dtReturn);
   }
   public delegate object[] CreateRowDelegate<T>(T t);
}
So putting it all together:
DataTable orders = ds.Tables["SalesOrderHeader"];

var ordersQuery = orders.ToQueryable();

var query = from o in ordersQuery
	    where o.Field<bool>("OnlineOrderFlag") == true
            select new { SalesOrderID = o.Field<int>("SalesOrderID"), OrderDate = o.Field<DateTime>("OrderDate") };

dtResults = query.ToADOTable( rec => new object[] {query});
Now dtResults is a table that can be queried from as in the example above.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform