Sub Statement - Variable as the Data Type for an Argument

  • Thread starter Thread starter Fernando
  • Start date Start date
F

Fernando

Hello, I apreciate if someone knows how to do this:

I have the following code:

*******************************************************
Public Sub LoadDataSet()
Dim objDataSetTemp As New Dataset_Names
Me.FillDataSet(objDataSetTemp)
End Sub
Public Sub FillDataSet(ByVal dataset As Dataset_Names)
Me.OleDbAdapter_Names.Fill(dataset)
End Sub
*******************************************************

My question is if someone knows how to make this code
usable for different "Datasets", example:

* Dataset_Names
* Dataset_Addresses
* Dataset_Documents

Or definitly I have to write the same code for each one
of the "Datasets"

Thanks for read this...
 
Hello, I apreciate if someone knows how to do this:


Or definitly I have to write the same code for each one
of the "Datasets"

Thanks for read this...

What are Dataset_Names, Dataset_Addresses, and Dataset_Documents? Are they
classes you have written yourself?

If they are derived from just a regular dataset, then change your sub to
take a dataset and you should be able to pass them in:

Public Sub FillDataSet(ByVal ds as Dataset)
'Code here
End Sub
 
"Object" seems to wotk always, hehe, and afterwards you can do a DirectCast

You can find an exepmle of DirectCast underneath this (with Forms).
Dim FormSource As frmSource

Dim FormTarget As frmTarget

Dim FormTest As Form

For Each FormTest In Me.MdiChildren

If TypeOf FormTest Is frmSource Then

FormSource = DirectCast(FormTest, frmSource)

FormSource.LeesBestanden()

ElseIf TypeOf FormTest Is frmTarget Then

FormTarget = DirectCast(FormTest, frmTarget)

FormTarget.LeesBestanden()

End If

Next


A nicer way is deriving your Dataset_Names, Dataset_Addresses and
Dataset_Documents from one type Dataset_Parent, and using this instead of
Object.

I hope this helpend some way.

Pieter
 
Hi Fernando,

I asume you use typed datasets (made with the designer)
With that is also a generated dataadaper, for which all commands are made
and therefore the dataset and the dataadapter are 1 to 1.

I do not think that it will be productive to make a generic routine for
that.
(you should pass the dataadapter and the dataset and that is more code than
the fill itself).

Just my thought about this.

Cor
 
Back
Top