How can i get the number of columns in A DataRow type?
Thanks.
Printable View
How can i get the number of columns in A DataRow type?
Thanks.
vb.net Code:
MyDataRow.ItemArray.Length
First of all thank you for the answer, but just before you post it I've found another way to achieve this target :
is there any difference?Code:MyDataRow.Table.Columns.Count
JM I was typing my post while you wrote your's, so the second methods is better?
I'm confused, you say avoid it because it gets the data, but the ItemArray is just a property same as Table and Columns? Is it not just getting some private level variable same as .Table and .Columns?
All in all it's probably much of a muchness. As I said, FA's approach actually creates an array containing the data to determine how many fields there are, which is not needed unless you're going to use the data. The other approach is more efficient I think you'll find, although the difference will be insignificant. I was also wrong about it not working with Detached rows.
No, it doesn't. This is courtesy of Reflector:vb.net Code:
Public Property ItemArray As Object() Get Dim defaultRecord As Integer = Me.GetDefaultRecord Dim objArray As Object() = New Object(Me._columns.Count - 1) {} Dim i As Integer For i = 0 To objArray.Length - 1 Dim column As DataColumn = Me._columns.Item(i) objArray(i) = column.Item(defaultRecord) Next i Return objArray End Get
Hmm... interesting!
Ok, Thanks a lot guys