ADO.Net result not simple

Using (or providing) Microsoft.NET Classes

ADO.Net result not simple

Postby neeraj on Tue Mar 17, 2015 12:42 pm

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
neeraj
 
Posts: 82
Joined: Wed Dec 02, 2009 12:10 am
Location: Ithaca, NY, USA

Re: ADO.Net result not simple

Postby PGilbert on Tue Mar 17, 2015 2:25 pm

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
PGilbert
 
Posts: 436
Joined: Sun Dec 13, 2009 8:46 pm
Location: Montréal, Québec, Canada

Re: ADO.Net result not simple

Postby StefanoLanzavecchia on Wed Mar 18, 2015 9:46 am

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.
User avatar
StefanoLanzavecchia
 
Posts: 109
Joined: Fri Oct 03, 2008 9:37 am

Re: ADO.Net result not simple

Postby neeraj on Wed Mar 18, 2015 6:09 pm

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.
neeraj
 
Posts: 82
Joined: Wed Dec 02, 2009 12:10 am
Location: Ithaca, NY, USA

Re: ADO.Net result not simple

Postby kai on Thu Mar 19, 2015 8:12 am

The link Pierre's provided should have been http://www.AplWiki.com/netDataTable
User avatar
kai
 
Posts: 137
Joined: Thu Jun 18, 2009 5:10 pm
Location: Hillesheim / Germany


Return to Microsoft.NET

Who is online

Users browsing this forum: No registered users and 1 guest