By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,384 Members | 927 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,384 IT Pros & Developers. It's quick & easy.

GetProperties

P: n/a
I am trying to get the properties of a DataTable or DataView using the
following code where obj is an object set to either a DataTable or DataView:

If TypeOf obj Is DataSet Then
myDataList = CType(CType(obj, DataSet).Tables(v_DataMember), _
IListSource).GetList
ElseIf TypeOf obj Is IListSource Then
myDataList = CType(obj, IListSource).GetList
End If
Dim obj As Object = v_DataList.Item(0)
Dim props As PropertyInfo() = myDataList.GetType.GetProperties()

Dim colname as string()
Redim colname(ubound(props)
For i = 0 to ubound(props)
colname(i) = props(i).Name
Next i

I get colname array as follows:
colname(0) = "DataView"
colname(1) = "Item"
colname(2) = "Item"
colname(3) = "Row"
colname(4) = "RowVersion"
colname(5) = "IsNew"
colname(6) = "IsEdit"
Where should be getting:
colname(0) = "Column1"
colname(1) = "Column2"
........

It seemed to work once then I must have changed something because it won't
work anymore. Any suggestions?

--
Dennis in Houston
Nov 21 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Dennis,

I was looking at your problem and had some questions however it is for you
nigth when it is for me day. Than I looked what you was really doing and
thought that it could be done more simple.

This was what I made
\\\
Dim myarraylist As New ArrayList
if TypeOf obj Is DataView Then
For Each col As DataColumn In _
DirectCast(obj, DataView).Table.Columns
myarraylist.Add(col.ColumnName)
Next
Else
For Each col As DataColumn In _
DirectCast(obj, DataSet).Tables(v_DataMember).Columns
myarraylist.Add(col.ColumnName)
Next
End If
///

I hope this helps

Cor

If TypeOf obj Is DataSet Then
myDataList = CType(CType(obj, DataSet).Tables(v_DataMember), _
IListSource).GetList
ElseIf TypeOf obj Is IListSource Then
myDataList = CType(obj, IListSource).GetList
End If
Dim obj As Object = v_DataList.Item(0)
Dim props As PropertyInfo() = myDataList.GetType.GetProperties()

Dim colname as string()
Redim colname(ubound(props)
For i = 0 to ubound(props)
colname(i) = props(i).Name
Next i

I get colname array as follows:
colname(0) = "DataView"
colname(1) = "Item"
colname(2) = "Item"
colname(3) = "Row"
colname(4) = "RowVersion"
colname(5) = "IsNew"
colname(6) = "IsEdit"
Where should be getting:
colname(0) = "Column1"
colname(1) = "Column2"
........

It seemed to work once then I must have changed something because it won't
work anymore. Any suggestions?

--
Dennis in Houston

Nov 21 '05 #2

P: n/a
Thanks Cor. That's the way I'll do it but I still wonder what's wrong with
the other code. I had gotten that technique from an article by Rockford
Lhotka on creating a Data Bound LIstView control. I had it working and then
did something stupid and couldn't get it to work again. Darn if I know what
I accidentally changed though. The code is pretty simple and works for
ArrayLists and Array's of Classes and STructures as well.

"Cor Ligthert" wrote:
Dennis,

I was looking at your problem and had some questions however it is for you
nigth when it is for me day. Than I looked what you was really doing and
thought that it could be done more simple.

This was what I made
\\\
Dim myarraylist As New ArrayList
if TypeOf obj Is DataView Then
For Each col As DataColumn In _
DirectCast(obj, DataView).Table.Columns
myarraylist.Add(col.ColumnName)
Next
Else
For Each col As DataColumn In _
DirectCast(obj, DataSet).Tables(v_DataMember).Columns
myarraylist.Add(col.ColumnName)
Next
End If
///

I hope this helps

Cor

If TypeOf obj Is DataSet Then
myDataList = CType(CType(obj, DataSet).Tables(v_DataMember), _
IListSource).GetList
ElseIf TypeOf obj Is IListSource Then
myDataList = CType(obj, IListSource).GetList
End If
Dim obj As Object = v_DataList.Item(0)
Dim props As PropertyInfo() = myDataList.GetType.GetProperties()

Dim colname as string()
Redim colname(ubound(props)
For i = 0 to ubound(props)
colname(i) = props(i).Name
Next i

I get colname array as follows:
colname(0) = "DataView"
colname(1) = "Item"
colname(2) = "Item"
colname(3) = "Row"
colname(4) = "RowVersion"
colname(5) = "IsNew"
colname(6) = "IsEdit"
Where should be getting:
colname(0) = "Column1"
colname(1) = "Column2"
........

It seemed to work once then I must have changed something because it won't
work anymore. Any suggestions?

--
Dennis in Houston


Nov 21 '05 #3

P: n/a
You are receiving the names of the properties of the DataList objject
(IListSource). Instead of attempting to get the names in this manner,
why not just use the DataView or DataTable as your source object.
Meaning - DataTable has a DefaultView Property which will allow you to
simply use only DataViews, or you can get the Source DataTable from the
DataView and use the DataTable only. Are you using any additional
properties of the IListSource Interface, or do you only need the Column
Names?

Kevin M. Schreiner
VP Software Architecture
Business Intelligence Force (bi4ce)

Nov 21 '05 #4

P: n/a
Thanks for reply. I need property/field names as well as Canread, canwrite.
My routine also accepts Arraylists and Array's of Structures and Classes. I
had the damn code working at one time but must have messed it up and for the
life of me I can't figure it out. I know how to do it using If statements
for TypeOf for DataView's, Datatables, DatsSets, etc. but the beauty of this
code was that it should work for any Ilist which all of these implement.

"kevin" wrote:
You are receiving the names of the properties of the DataList objject
(IListSource). Instead of attempting to get the names in this manner,
why not just use the DataView or DataTable as your source object.
Meaning - DataTable has a DefaultView Property which will allow you to
simply use only DataViews, or you can get the Source DataTable from the
DataView and use the DataTable only. Are you using any additional
properties of the IListSource Interface, or do you only need the Column
Names?

Kevin M. Schreiner
VP Software Architecture
Business Intelligence Force (bi4ce)

Nov 21 '05 #5

P: n/a
Dennis,

Maybe now you tell this I will try it in the weekend, not today anymore.
However my question was what type is "myDataList".

I have seen this one as well in C# code. And once did it in VBNet however I
did not save it.

No promises of course.

Cor

"Dennis" <De****@discussions.microsoft.com>
Thanks for reply. I need property/field names as well as Canread,
canwrite.
My routine also accepts Arraylists and Array's of Structures and Classes.
I
had the damn code working at one time but must have messed it up and for
the
life of me I can't figure it out. I know how to do it using If statements
for TypeOf for DataView's, Datatables, DatsSets, etc. but the beauty of
this
code was that it should work for any Ilist which all of these implement.

"kevin" wrote:
You are receiving the names of the properties of the DataList objject
(IListSource). Instead of attempting to get the names in this manner,
why not just use the DataView or DataTable as your source object.
Meaning - DataTable has a DefaultView Property which will allow you to
simply use only DataViews, or you can get the Source DataTable from the
DataView and use the DataTable only. Are you using any additional
properties of the IListSource Interface, or do you only need the Column
Names?

Kevin M. Schreiner
VP Software Architecture
Business Intelligence Force (bi4ce)

Nov 21 '05 #6

P: n/a
myDataList is dimensioned as

Dim myDataList as IList

Thanks for help. Hope you can get it working.

"Cor Ligthert" wrote:
Dennis,

Maybe now you tell this I will try it in the weekend, not today anymore.
However my question was what type is "myDataList".

I have seen this one as well in C# code. And once did it in VBNet however I
did not save it.

No promises of course.

Cor

"Dennis" <De****@discussions.microsoft.com>
Thanks for reply. I need property/field names as well as Canread,
canwrite.
My routine also accepts Arraylists and Array's of Structures and Classes.
I
had the damn code working at one time but must have messed it up and for
the
life of me I can't figure it out. I know how to do it using If statements
for TypeOf for DataView's, Datatables, DatsSets, etc. but the beauty of
this
code was that it should work for any Ilist which all of these implement.

"kevin" wrote:
You are receiving the names of the properties of the DataList objject
(IListSource). Instead of attempting to get the names in this manner,
why not just use the DataView or DataTable as your source object.
Meaning - DataTable has a DefaultView Property which will allow you to
simply use only DataViews, or you can get the Source DataTable from the
DataView and use the DataTable only. Are you using any additional
properties of the IListSource Interface, or do you only need the Column
Names?

Kevin M. Schreiner
VP Software Architecture
Business Intelligence Force (bi4ce)


Nov 21 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.