replica nfl jerseysreplica nfl jerseyssoccer jerseyreplica nfl jerseys forums.silverfrost.com :: View topic - Elements of DotNet Collection
forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Elements of DotNet Collection

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support
View previous topic :: View next topic  
Author Message
Astelix



Joined: 17 Dec 2008
Posts: 13

PostPosted: Wed Dec 24, 2008 1:46 pm    Post subject: Elements of DotNet Collection Reply with quote

How can I access the elements of a dotnet collection (e.g. a DataTable in the System.Data.DataTablesCollection)?

It seems to be immpossible with the Index, because you cannot declare a collection as an array. If you try, you get

Error 1 Conversion from System.Data.DataTableCollection to System.Data.DataTableCollection[] not possible.

Also the collection ist not an Array of DataTables like this:
"System.Data.DataTable[]"


If you declase the collection as a scalar and try to access its elements with the index position you get

Error 1 Array TABS appears in this expression as rank 1, but was declared as a scalar

There seems to be no other accessor method that could be declared via ASSEMLY_EXTERNAL.

What's the trick here?
Question
Back to top
View user's profile Send private message
Astelix



Joined: 17 Dec 2008
Posts: 13

PostPosted: Sat Dec 27, 2008 5:12 pm    Post subject: Reply with quote

If it is really impossible to to answer this question (I can't believe that or I'm missing a very obvious thing) then a I have related question:

Has anybody a working example for reading/writing a MS-Access Database, SQL-Server Database or Excel-Sheet via OleDb, ODBC, DAO, ADO.NET or some other .Net-way?
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 8210
Location: Salford, UK

PostPosted: Sat Dec 27, 2008 7:43 pm    Post subject: Reply with quote

I do not know if I can help with this but I recommend that you set your question in the context of some sample code to illustrate clearly what you aim to do and what fails to happen.
Back to top
View user's profile Send private message AIM Address
Astelix



Joined: 17 Dec 2008
Posts: 13

PostPosted: Sat Dec 27, 2008 8:32 pm    Post subject: Reply with quote

Here is the program:

program ReadMDB

library ("System")
library ("System.Data")
implicit none

object("System.Data.OleDb.OleDbCommand") :: myCommand
object("System.Data.OleDb.OleDbDataAdapter") :: myDataAdapter
object("System.Data.OleDb.OleDbConnection") :: myConn
object("System.Data.DataTableCollection") :: tabs
!trying to define as array produces error 1a and 2a below
!object("System.Data.DataTableCollection[]") :: tabs
object("System.Data.DataSet") :: myDataSet
object("System.Data.DataTable") :: myTab

string :: strConn
string :: strSelect
integer :: res

assembly_external(name="System.Data.OleDb.OleDbConnection.Open") dc_open
assembly_external(name="System.Data.OleDb.OleDbConnection.Close") dc_close
assembly_external(name="System.Data.OleDb.OleDbDataAdapter.Fill") da_fill



strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Test.mdb"
strSelect = "SELECT * FROM tblTest"

myConn = new@("System.Data.OleDb.OleDbConnection",strConn)
myCommand = new@("System.Data.OleDb.OleDbCommand",strSelect,myConn)
myDataAdapter = new@("System.Data.OleDb.OleDbDataAdapter",myCommand)
myDataSet = new@("System.Data.DataSet")


res=da_fill(myDataAdapter,myDataSet,"Test")
tabs=MyDataset%Tables



print*, res
!result ok. Numer of selected records
print*, tabs%count
!ok. 1 table

!HOW DO I ACCESS THE ELEMENTS OF THE DATATABLECOLLECTION tabs (or any other collection?)
mytab=tabs(0)
!Error 1 Array TABS appears in this expression as rank 1, but was declared as a scalar D:\Visual Studio 2008\Projects\F95Projects\ReadFromAccess\ReadFromAccess\ReadMdb.F95 41
!Error 2 Conversion from System.Data.DataTableCollection to System.Data.DataTable not possible D:\Visual Studio 2008\Projects\F95Projects\ReadFromAccess\ReadFromAccess\ReadMdb.F95 41
!if tabs is defined as DataTableCollection[]
!Error 1a Conversion from System.Data.DataTableCollection to System.Data.DataTableCollection[] not possible D:\Visual Studio 2008\Projects\F95Projects\ReadFromAccess\ReadFromAccess\ReadMdb.F95 39
!Error 2a Member count does not exist (or is not publicly accessible) in OBJECT('System.Data.DataTableCollection[]') D:\Visual Studio 2008\Projects\F95Projects\ReadFromAccess\ReadFromAccess\ReadMdb.F95 44

!trying to access default attribute:
!mytab=tabs%item(0) ! produces
!Error 1 Internal compiler error D:\Visual Studio 2008\Projects\F95Projects\ReadFromAccess\ReadFromAccess\ReadMdb.F95 54



read *
call dc_close(myConn)


end program
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 8210
Location: Salford, UK

PostPosted: Mon Dec 29, 2008 10:53 am    Post subject: Reply with quote

I have had a look at your code and can confirm that you cannot access an item in a .NET collection via its index. If I wanted to do this I would consider writing a C# function to extract the item. This function would be included in a C# DLL which I would then access from my Fortran code.
Back to top
View user's profile Send private message AIM Address
Astelix



Joined: 17 Dec 2008
Posts: 13

PostPosted: Mon Dec 29, 2008 2:08 pm    Post subject: Reply with quote

Thank you Paul, that works. It is usable as a workaround.

But given the central role of collections and other higher order datatypes (e.g. dictionaries) that are variants of linked lists and hashtables you should really implement some form of direct support for them. Without that the Dotnet-support is really "basic". You can use only a very resticted part of the framework without the help of other dotnet languages.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group