[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 215
  • Last Modified:

M:N junction table - errors in copied code

I copied this code directly from the book (again), and once again, I've got errors. (of course, I added the adapters, connections, etc, on my own - so maybe that's where I fouled it up).

Anyway - in the form/presentation, I have an error on this line:

strTitles = mobjAuthors.getData(strAuthorID)

it was delcared as:
Dim strTitles(10) As String

and I get:  "Value of type 'string' cannot be convert to '1 dimensional array of string'"

Then in my PubsDatabase data tier, I get the same error in my getData function:

  drsTitleAuthor = drAuthor.GetChildRows("authorstitleauthor")  <--- this line
 [...]
  Return strTitles  <--- and this one : (

Anyone want to help me?

Entire project is here: https://filedb.experts-exchange.com/incoming/ee-stuff/110-ch4.zip
0
sirbounty
Asked:
sirbounty
  • 5
  • 2
2 Solutions
 
SanclerCommented:
It's brackets ;-)

Change this

    Public Function getData(ByVal strAuID As String) As String

to this

    Public Function getData(ByVal strAuID As String) As String()

and, within that function, this

        Dim drsTitleAuthor As DataRow       'Array of matching rows from junction table



to this

        Dim drsTitleAuthor() As DataRow       'Array of matching rows from junction table

The function needs to return an array of string, not a single string, and drsTitleAuthor needs to be an array of datarows, not a single datarow.

Roger
0
 
sirbountyAuthor Commented:
Ah -  I did miss that.
However, the second item is actually in the book as

Dim drsTitleAuthor As DataRow()

What's the difference?

Errors are gone from the code, but running it generates an error on:
 .ValueMember = "au_id"

"Could not bind to new display member.  Parameter name: newDisplayMember"

When I look at dvNames, it's not bound to a table.  So, I set it to authors, and now all I get in my combo appears to be the ID (au_id), rather than the DisplayMember "Name"...nor does selecting anything appear to populate the listbox.

Thanx, as usual.. :^)
0
 
SanclerCommented:
>>
What's the difference?
<<

I'm not sure there is one, at least for any purpose that's relevant here.

   Dim objName() as object 'creates an array which can contain objects.
   Dim objName as object() 'creates an object which can contain an array of objects  

>>
When I look at dvNames, it's not bound to a table.  So, I set it to authors
<<

So far so good

>>
now all I get in my combo appears to be the ID (au_id), rather than the DisplayMember "Name"
<<

The authors table doesn't have a column called "Name".  There's either the need for the sort of exercise you did on one of the earlier chapters to put LastName, MiddleInitial and FirstName into a column marked "Name" and use that, or if you want to use one of the existing columns it will have to be "au_lname"

>>
nor does selecting anything appear to populate the listbox
<<

It won't.  The cboNames_SelectedIndexChanged sub calls

                strTitles = mobjAuthors.getData(strAuthorID)

That contains this

        'Retrieve the array of matching rows from the junction table
        drsTitleAuthor = drAuthor.GetChildRows("authorstitleauthor")

and this

            'Retrieve the parent row and title field from the junction table row
            strTitle = drTitleAuthor.GetParentRow("titlestitleauthor").Item("title")

Both of those rely on the existence of datarelations "authorstitleauthor" and "titlestitleauthor" which don't exist.  As those seem to be so crucial to the current exercise, I imagine the 'book' must say, somewhere, how they should be created.

Roger

PS, sorry for the time lapse.  My earlier posting was at 2.30 a.m. local time.  I'd been up for a short while but then went straight back to bed.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
sirbountyAuthor Commented:
No need for an apology - you have been a wealth of help to me.

The thing I don't like about this book is - it starts explaining new techniques - then it 'walks' you through designing it step-by-step.  Next it starts building on those fundamentals, but not in the same step-by-step manner.  More like, "And when you want to do xyz on top of what you've already learned, you simply blah blah blah."  But it never details what blah blah blah is...  But I suppose the end of the chapter hands-on, is supposed to remedy that (which comes next).

This prelude to that only showed the form layout and supplied the code.  So, I had to try and build on past techniques to develop this one.  I don't guess I did so terrible looking at what the hiccups have turned out to be here (thanx largely in part to Roger - The ADO.Net guy - haha :)

So, it looks like you're right.  That was my mistake (again) for not looking at the table.  I 'assumed' that Name was the field, when I copied the code.  Do the error messages ever get easier to understand?  : |

Ok, so everything up to the cbo-change event is working fine now.  I don't recall seeing anything 'specific' about those relations, but I'll look again.  A million thanx to you.
0
 
Bob LearnedCommented:
BTW, what is the name of the book, so I can remember to keep away from it? :(

Bob
0
 
sirbountyAuthor Commented:
Haha - Advanced Programming using VB.Net.  It's probably more 'me' than anything.  
The joys of distance learning...

I see where the relationships are mentioned, but it doesn't seem to detail how to set them up exactly.
Obviously, I'd (re)configure the dataadapter to include the other table - would I also generate a new dataset? (hope that's not too ignorant of a question).
0
 
sirbountyAuthor Commented:
Nevermind - I think I found it.  Open the schema, right-click, add-new-relationship.
Stay tuned...
0
 
sirbountyAuthor Commented:
Happy, happy - joy, joy.

Stepping through the project really (imo) helps to understand how the classes interact.
It's working like a charm!

It's outside the scope of this project I think, but here's one thing I noted:  When the class component is called (getData function), strTitles array is populated based upon the Row element.  Then the entire array is returned.  In my first run-through, the author had 2 titles.  So, an array with a ubound of 1 was returned.

When it gets back to the form though, the form has to loop through the entire array length (which was set at 10).
Supposedly/hopefully, there is a way to dynamically set this?  No need to explain how, cause this one's done, but I thought that seemed like it would make the project a nanosecond or two, more efficient.

Thank you once again Roger.  Not only did you help me get this working, but you helped you helped me understand what it took to get it working.

Now, on to the Hands-On...wish me luck! :^)

~Neal
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now