From: mynamehere@comcast.net   
      
   "Bert Tuijl (thuis)" wrote in message   
   news:dc642$4453ee9d$3ea35736$28060@news.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   
   > 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'   
   >   
      
   First, you should ask your .Net questions in a dotnet group, not a VB6 group.   
      
   Second, since myDataSet inherits from DataSet, that means that:   
    All instance of myDataSet are also an instance of DataSet, but   
    Not all instances of DataSet are also an instance of myDataSet.   
      
   You can't "get rid of this nasty exception"; you actually can't cast a generic   
   DataSet to myDataSet, since it isn't one!   
      
   Perhaps you meant for your web service function dswebsvc() to return an   
   instance   
   of myDataSet?   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|