Answered by:
How to get properties of variable of type Object which have assigned e.g. DataSet1

Question
-
For example I have project named TestRelation :
When I assign in this project to variable ObjDs of type Object e.g. any DataSet1 binding to Form1.
Dim ObjDs As Object = TestRelation.DataSet1
How can I then after assigning Object = TestRelation.DataSet1,read TestRelation.DataSet1 properties from this variable ObjDs.
Is it possible?
Or I have to retype first this ObjDs variable again to DataType TestRelation.DataSet1?
Or enough retype this ObjDs only to universal variable of DataType System.Data.DataSet?
Friday, June 12, 2015 10:25 AM
Answers
-
How can I then after assigning Object = TestRelation.DataSet1,
read TestRelation.DataSet1 properties from this variable ObjDs.
You have to cast the variable to an object of the correct type.
https://msdn.microsoft.com/en-us/library/vstudio/7k6y2h6x(v=vs.120).aspx
But it is much simpler to declare it as the correct type in the first place. Dim ObjDs As System.Data.Dataset = TestRelation.DataSet1
- Proposed as answer by Magnus (MM8)MVP Friday, June 12, 2015 12:01 PM
- Marked as answer by Vyvoj DS Friday, June 12, 2015 12:27 PM
Friday, June 12, 2015 10:33 AM
All replies
-
How can I then after assigning Object = TestRelation.DataSet1,
read TestRelation.DataSet1 properties from this variable ObjDs.
You have to cast the variable to an object of the correct type.
https://msdn.microsoft.com/en-us/library/vstudio/7k6y2h6x(v=vs.120).aspx
But it is much simpler to declare it as the correct type in the first place. Dim ObjDs As System.Data.Dataset = TestRelation.DataSet1
- Proposed as answer by Magnus (MM8)MVP Friday, June 12, 2015 12:01 PM
- Marked as answer by Vyvoj DS Friday, June 12, 2015 12:27 PM
Friday, June 12, 2015 10:33 AM -
Thank you for your answer.
It works OK.
But tell me please still if you can,
then what about e.g. DataTable1TableAdapter.
Inside this DataSet1 a have DataTable1.
To the Form1 I have then bounded too DataTable1TableAdpter.
Then when I assign
Dim ObjTabAdapter As Object = Me.DataTable1TableAdapter
How can I read properties of ObjTabAdapter.
Exist too for my specific DataType
TestRelation.DataSet1TableAdapters.DataTable1TableAdapter
any universal datatype?Similar as my specific types TestRelation.DataSet1 have the universal System.Data.DataSet ?
What can be then similar universal type for my specific TestRelation.DataSet1TableAdapters.DataTable1TableAdapter DataType?
- Edited by Vyvoj DS Friday, June 12, 2015 12:35 PM
Friday, June 12, 2015 12:26 PM -
Then when I assign
Dim ObjTabAdapter As Object = Me.DataTable1TableAdapter
How can I read properties of ObjTabAdapter.Whether the Type is a Type that is defined by the framework, or a Type that is defined by your data set doesn't make any difference, except in the way that you need to specify the name.
It appears that you are using strongly typed data sets. This means that the Type to use in the Dim statement is a Type that is defined by the dataset that you created. See the discussion here:
https://msdn.microsoft.com/en-us/library/esbykkzb(v=vs.110).aspxTherefore the name of the Type to use in the DIM will include your particular dataset.
Dim ObjTabAdapter As TestRelation.DataSet1TableAdapters.DataTable1TableAdapter = TestRelation.DataSet1TableAdapters.DataTable1TableAdapter
It is very important to be clear about the difference between a Type defined (as a class) within a dataset on the one hand and, on the other hand, the variable name used for the instance of that type that is created by the binding.
See here for comments on Class, Type, Instance and Variable:
https://vbdotnetblog.wordpress.com/overview/oop-terminology/
Friday, June 12, 2015 10:41 PM