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
LVL 67
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.

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.. :^)
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.


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.

Experts Exchange Solution brought to you by ConnectWise

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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.
Bob LearnedCommented:
BTW, what is the name of the book, so I can remember to keep away from it? :(

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).
sirbountyAuthor Commented:
Nevermind - I think I found it.  Open the schema, right-click, add-new-relationship.
Stay tuned...
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! :^)

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.