Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Jul 12, 2009 03:30 PM by PeteNet
Member
134 Points
457 Posts
Jul 10, 2009 08:10 AM|LINK
Hi
I tried to convert a datatable to an array:
Dim dr As DataRow Dim dc As DataColumn For Each dr In objRS(K).Rows For Each dc In objRS(K).Columns alldataArray = dr(dc) Next Next
But hit with errors when tried these 2 action:
numrows = UBound(alldataArray, 2) thisfield = alldataArray(1, 2)
Both throws me this error: No default member found for type 'DBNull'.
Please help.
Thank You.
Star
12156 Points
2355 Posts
Jul 12, 2009 10:51 AM|LINK
Check out the CopyTo method of the Rows collection, http://msdn.microsoft.com/en-us/library/ms135383.aspx.
The UBound method should be replaced with the GetUpperBound method of the array variable, or simply the Length property.
All-Star
81342 Points
11398 Posts
Jul 12, 2009 03:30 PM|LINK
int rowcount = dt.Rows.Count; DataRow[] dr= new DataRow[rowcount]; dt.Rows.CopyTo(dr,0);
where dt is your DataTable
ryanlcs
Member
134 Points
457 Posts
Convert Datatable to Array
Jul 10, 2009 08:10 AM|LINK
Hi
I tried to convert a datatable to an array:
Dim dr As DataRow Dim dc As DataColumn For Each dr In objRS(K).Rows For Each dc In objRS(K).Columns alldataArray = dr(dc) Next NextBut hit with errors when tried these 2 action:
Both throws me this error: No default member found for type 'DBNull'.
Please help.
Thank You.
integrasol
Star
12156 Points
2355 Posts
Re: Convert Datatable to Array
Jul 12, 2009 10:51 AM|LINK
Check out the CopyTo method of the Rows collection, http://msdn.microsoft.com/en-us/library/ms135383.aspx.
The UBound method should be replaced with the GetUpperBound method of the array variable, or simply the Length property.
Carsten
Please click Mark as Answer if this post is of help to you. :-)
My Blog
PeteNet
All-Star
81342 Points
11398 Posts
Re: Convert Datatable to Array
Jul 12, 2009 03:30 PM|LINK
int rowcount = dt.Rows.Count;
DataRow[] dr= new DataRow[rowcount];
dt.Rows.CopyTo(dr,0);
where dt is your DataTable
Peter