ADO.Net result not simple

Using (or providing) Microsoft.NET Classes
Post Reply
neeraj
Posts: 82
Joined: Wed Dec 02, 2009 12:10 am
Location: Ithaca, NY, USA

ADO.Net result not simple

Post by neeraj »

I am using ADO.Net to run some queries and get databack using the
      2011⌶


For some columns I get back a vector of
      B.GetType
System.Int64


I can convert this to simple APL type using
      ⍎⍕


Is there a better way?

Thanks
User avatar
PGilbert
Posts: 440
Joined: Sun Dec 13, 2009 8:46 pm
Location: Montréal, Québec, Canada

Re: ADO.Net result not simple

Post by PGilbert »

In case that you have a .net DataTable and you want to convert one column to Apl, this function taken from http://www.AplWiki.com/netDataTable may help you:(link corrected, thanks Kai)

Code: Select all

       apl←dt GetCol colNumber;colName;⎕USING;string;dv
     ⍝ Get the value of a single column of an existing DataTable
     ⍝ dt        = Data Table
     ⍝ colNumber = Index of the column (Origin 1)
     ⍝ apl       = Apl data
     
     ⍝ Get the name of the column
      colName←dt.Columns[colNumber-1].ColumnName
     
     ⍝ Create a .net string vector (string[]) with that name
      ⎕USING←'' 'System.Data,System.Data.dll'
      string←System.Array.CreateInstance(System.Type.GetType⊂'System.String')1
      string.SetValue(colName 0)
     
     ⍝ Make a DataView and filter the method .ToTable
      dv←⎕NEW DataView dt
      apl←,2011⌶dv.ToTable(0 string)
Last edited by PGilbert on Thu Mar 19, 2015 12:38 pm, edited 1 time in total.
User avatar
StefanoLanzavecchia
Posts: 113
Joined: Fri Oct 03, 2008 9:37 am

Re: ADO.Net result not simple

Post by StefanoLanzavecchia »

System.Int64 is not a type whose instances you can represent without loss of precision as native types in Dyalog APL. As long as the integer it wraps is less than 2*53 then you'll be fine. If it's larger then 2*53 (and with an Int64 you have another 11 bits to make your number much bigger) then you won't be fine... Because the trick of executing the formatted version is going to give you a truncated float.
neeraj
Posts: 82
Joined: Wed Dec 02, 2009 12:10 am
Location: Ithaca, NY, USA

Re: ADO.Net result not simple

Post by neeraj »

Thanks Pierre for all the code on APLWiki. It is so useful to have samples available. Stefano the numbers are small (less than 100), it is the UID field in syslogins table but it comes back as Int64. I anticipate a lossless conversion.
User avatar
kai
Posts: 141
Joined: Thu Jun 18, 2009 5:10 pm
Location: Hillesheim / Germany

Re: ADO.Net result not simple

Post by kai »

The link Pierre's provided should have been http://www.AplWiki.com/netDataTable
Post Reply