-
Jul 7th, 2009, 01:15 AM
#1
[RESOLVED] DataRow column count
How can i get the number of columns in A DataRow type?
Thanks.
* Rate It If you Like it
__________________________________________________________________________________________
" Programming is like sex: one mistake and you’re providing support for a lifetime."
Get last SQL insert ID
-
Jul 7th, 2009, 01:17 AM
#2
Re: DataRow column count
vb.net Code:
MyDataRow.ItemArray.Length
-
Jul 7th, 2009, 01:20 AM
#3
Re: DataRow column count
Originally Posted by ForumAccount
vb.net Code:
MyDataRow.ItemArray.Length
I'd avoid that because it actually gets the data to determine the number of fields. I'd tend to go with myDataRow.Table.Columns.Count. That said, that will not work on rows that have been created but not added to the table.
-
Jul 7th, 2009, 01:21 AM
#4
Re: DataRow column count
First of all thank you for the answer, but just before you post it I've found another way to achieve this target :
Code:
MyDataRow.Table.Columns.Count
is there any difference?
* Rate It If you Like it
__________________________________________________________________________________________
" Programming is like sex: one mistake and you’re providing support for a lifetime."
Get last SQL insert ID
-
Jul 7th, 2009, 01:22 AM
#5
Re: DataRow column count
JM I was typing my post while you wrote your's, so the second methods is better?
* Rate It If you Like it
__________________________________________________________________________________________
" Programming is like sex: one mistake and you’re providing support for a lifetime."
Get last SQL insert ID
-
Jul 7th, 2009, 01:24 AM
#6
Re: DataRow column count
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?
-
Jul 7th, 2009, 01:27 AM
#7
Re: DataRow column count
Originally Posted by motil
JM I was typing my post while you wrote your's, so the second methods is better?
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.
-
Jul 7th, 2009, 01:30 AM
#8
Re: DataRow column count
Originally Posted by ForumAccount
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?
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
-
Jul 7th, 2009, 01:34 AM
#9
-
Jul 7th, 2009, 01:38 AM
#10
* Rate It If you Like it
__________________________________________________________________________________________
" Programming is like sex: one mistake and you’re providing support for a lifetime."
Get last SQL insert ID
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|