GetChildRows error - what the f@&# !

D

Daniel

What's wrong with this code?

1 Dim parentRow, childRow as DataRow
2
3 For i = 0 To mainDataTable.Rows.Count - 1
4 parentRow = mainDataTable.Rows(i)
5 childRow = parentRow.GetChildRows("DataRelation")
6 mainDataTable.Rows(i).Item("Column1") = childRow.Item("Column1")
7 next i

mainDataTable is a plain old DataTable already instantiated.
DataRelation is the name of a valid DataRelation object in the DataSet
that joins these two tables.

I get this error at line 5:

"Value of type '1-dimensional array of System.Data.DataRow' cannot be
converted to 'System.Data.DataRow'.

What conversion is it talking about? I'm loading a DataRow object with
a DataRow object!!!

Any help is greatly appreciated,
Daniel
 
T

Theo Verweij

I, and I think a lot of other posters in this form, would like it if you
wouldn't hide your own incompetence with bad words.

Your problem is quite simple; you are assigning an array of rows
(parentRow.GetChildRows("DataRelation")) to a row.
And that's not possible.
 
D

Daniel

Oh good grief. Well thanks for your answer, but I can do without the
moral correction, especially since I'm not hiding incompetence. I'm
throwing my FRUSTRATION and CONFUSION right out there for all to see.
And I didn't say any "bad words". Hope you didn't melt or turn into a
pumpkin or something after reading such atrocious language, er,
symbols.

For your information, my confusion was in the fact that my code almost
exactly matches the code Microsoft uses in the help file for the
GetChildRows method (see excerpt below):

Dim instance As DataRow
Dim relation As DataRelation
Dim returnValue As DataRow()

returnValue = instance.GetChildRows(relation)


They don't show that GetChildRows requires an index after the call. I
found that though by searching more closely in the example they give
farther down the page. So thanks for helping me, and also making me a
holier person.
 
T

Tim Patrick

Frankly, I don't even know why you had to say "what the form" (or mask it
with punctuation) when your question wasn't about Windows Forms at all. ;-)
 
T

Theo Verweij

And you still don't see the error in your own code; the ms code is
correct and your code is (like you said) almost like it (except for the
bug in your code).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top