home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.visual.basic      MS Visual Basic discussions, NOT dot-net      10,840 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 10,042 of 10,840   
   Bert Tuijl (thuis) to All   
   Behaviour of CType   
   30 Apr 06 00:54:22   
   
   From: b.tuyl@chello.nl   
      
   Can someone explain this new-to-visualbasic programmer why my statement   
   throws an exception?   
      
   I have defined a class:   
   Class myDataSet   
       Inherits System.Data.DataSet   
       Public Sub fun(ByVal someparm As String)   
           dosomething()   
       End Sub   
   End Class   
      
   And I created a webservice function that returns a System.Data.DataSet   
   I try to stuff this dataset into my own dataset-type   
   dim myDataSet mds as myDataSet = new myDataSet   
   'mds = dswebsvc(arg) ' vbcompiler does not allow this but rather:   
   mds = CType( dswebsvc(arg), myDataSet) ' compiler allows this   
      
   But at runtime, this statement throws an exception with the message:   
   Unable to cast object of type 'System.Data.DataSet' to type 'myDataSet'   
      
   To overcome this problem I tried to overload the CType() function in the   
   myDataSet class but that is not allowed since apparently the compiler   
   automatically generates this overload!   
      
   What can I do to get rid of this nasty exception?   
      
   Bert   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca