Re: Overloading Update method by David
David
Mon Oct 27 16:50:31 CST 2003
"Aaron Ackerman" <no@spam.com> wrote in message
news:uYG2XSNnDHA.2304@TK2MSFTNGP11.phx.gbl...
> I want to overload a userdefined method named update so that I pass in
> different typed datasets and through a case statement it would then update
> using the appropriate dataadapter. Is this possible and if so how would
the
> check go to look for the particular typed dataset? Also how do I define
the
> method?
>
>
You wouldn't need a case stateement AND overloads. One or the other.
The thing to remember is that strongly typed datasets are subtypes of
DataSet, and so can be passed into any method that acceptes a DataSet. And
the compiler will always pick the most specific overload based on the
declared type being passed into the method.
So either define a single update, and test the type inside:
Public sub Update(ds as DataSet)
if typeof(ds) is myTypedDataSet1 then
'special logic for myTypedDataSet1
elseif typeof(ds) is myTypedDataSet2 then
'special logic for myTypedDataSet1
else
'generic dataset update code
end if
end sub
Or define multiple overloads.
Public sub Update(ds as DataSet)
'generic dataset update code
end sub
Public sub Update(ds as MyDataSet1)
'special logic for myTypedDataSet1
end sub
Public sub Update(ds as MyDataSet2)
'special logic for myTypedDataSet2
end sub
David