Page 1 of 1
ADO.Net result not simple
Posted: Tue Mar 17, 2015 12:42 pm
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
Re: ADO.Net result not simple
Posted: Tue Mar 17, 2015 2:25 pm
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)
Re: ADO.Net result not simple
Posted: Wed Mar 18, 2015 9:46 am
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.
Re: ADO.Net result not simple
Posted: Wed Mar 18, 2015 6:09 pm
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.
Re: ADO.Net result not simple
Posted: Thu Mar 19, 2015 8:12 am
by kai
The link Pierre's provided should have been
http://www.AplWiki.com/netDataTable