-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Problem trying to get a datatable from an IList or an IQuery
PostPosted: Fri Oct 07, 2005 11:12 pm 
Newbie

Joined: Sat Sep 17, 2005 5:48 am
Posts: 9
I saw another post in this forum demonstrating how to create a datatable from either Ilist or IQuery but I cant seem to get it to work and I am wondering if the code is wrong. I am desperate to get this working. Heres the code

Code:
public class TypedListGenerator {
   public TypedListGenerator(IList nestedArrays) {
      this._nestedArrays = nestedArrays;
      this._view = new DataTable();
   }
   
   IList _nestedArrays;
   DataTable _view;
   
   public void AddColumn(string name) {
      this.AddColumn(name, typeof(String));
   }
   
   public void AddColumn(string name, Type type) {
      this._view.Columns.Add(name, type);
   }
   
   public ITypedList Format() {
      if(this._view.Rows.Count != this._nestedArrays.Count) {
         foreach(object[] row in this._nestedArrays) {
            this._view.Rows.Add(row);
         }
      }
       
      return this._view.DefaultView;
   }   
}



The code breaks on the line:

foreach(object[] row in this._nestedArrays)

with the error :

specified cast is not valid.

I cant see why, I realise this might be more of a .net problem but I'm not sure.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 08, 2005 7:29 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
_nestedArrays doesn't contains object[], you need to find the type of the elements in _nestedArrays and use it (it is either an entity, an IList or a simple field).

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 12, 2005 6:29 am 
Newbie

Joined: Sat Sep 17, 2005 5:48 am
Posts: 9
I hate to have to ask, but how could i find out?

Thanks again


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 12, 2005 2:04 pm 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
As I said, it is either an entity, an IList or a simple field; so, you can write something like:
Code:
if( o is IList) ...
else if( o is ...) ...


I think that System.Type has a IsValue() or something like that to know if it is a "simple field".
For IList, you probably need to do a recursive call...

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


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

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.