An OdbcParameter with ParameterName '@lname' is not contained by this OdbcParameterCollection.

Please see the project attachment located at the original post: http://www.experts-exchange.com/Q_21851169.html

The 'only' changes I've made are to include an expression in my schema.

Here's the steps that I took:

Opened dsEmployee.xsd, scrolled to the last line (the *), selected E (Element), typed "Name" in the first column (second was string), then I changed the Expression property to "fname + ' ' + mint + ' ' + lname"

I chose Build/Rebuild Solution.

THen, I changed the text property of my label (Label3) from First Name to Full Name.
Changed the name property from lblFirstName to lblName, and set it's binding (text) property to Name instead of DsEmployee1.

What did I miss?  Where did I go wrong?  <sigh>
LVL 67
sirbountyAsked:
Who is Participating?
 
SanclerCommented:
None of the controls - apart from the combobox - are bound to anything.  So (a) lblHireDate.Text will never be anything different from "", which accounts for the error message about an invalid cast and (b) even if that line is removed or commented out, to get rid of that error message, none of the other fields (i.e. controls) will be populated.

As I said before "it looks like making these changes must have caused the Automatic code generator to overwrite (at least some of) the code you amended/inserted".  And some of the overwrites must have been of the databindings that were in the previous version.  Those were

        Me.lblEmployeeID.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.DsEmployee1, "employee.emp_id"))
        Me.lblHireDate.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.DsEmployee1, "employee.hire_date"))
        Me.lblFirstName.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.DsEmployee1, "employee.fname"))

What you need to do is get those lines back into your code somewhere.  You will, of course, need to change any the references that you have changed - like changing DsEmployee1 to DsEmployee2.  And rather than putting the lines in the Window Generated Code Region (which is where they originally came from) I suggest you put them, after any necessary amendments, in the form load sub.

Roger
0
 
SanclerCommented:
Did you get any errors/warnings when you made the change to dsEmployee.xsd and then Rebuilt?  I ask because the field name is 'minit', not 'mint' as in your post above, and that would throw things out - although with error messages different from the one you now report.

The code you're now using is different from that attached to your original post if only because you had, to get that working, to put in a SelectCommand.Parameters.Add statement in somewhere.  The error you're now reporting seems to relate to that.  So can you post the code that deals with that, and say where it appears in the program - e.g. Windows Generated Region, form load sub, whatever?

Roger
0
 
sirbountyAuthor Commented:
I didn't - and you're right, it was misspelled - plus it wasn't in my statement to begin with.
I don't know what I've done now...I'll repost the project as it is now.
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

 
SanclerCommented:
As you've just posted, the Expression in the .xsd for Name is still wrong.  Change it to minit and rebuild.

Then it looks like making these changes must have caused the Automatic code generator to overwrite (at least some of) the code you amended/inserted.  The parameter you want is now named 'lname'.  It's in this line in the Windows Generated Region.

        Me.OdbcSelectCommand1.Parameters.Add(New System.Data.Odbc.OdbcParameter("lname", System.Data.Odbc.OdbcType.NVarChar, 30, "lname"))

Rather than fiddling with that, I suggest you change the line in the cboLastName_SelectedIndexChanged sub from

            daEmployee.SelectCommand.Parameters("@lname").Value = cboLastName.Text

to

            daEmployee.SelectCommand.Parameters("lname").Value = cboLastName.Text

I haven't, by the way, tested.  I don't really want to set up an ODBC connection to do so.  But it LOOKS OK apart from that.

Roger
0
 
sirbountyAuthor Commented:
Ok - made the changes. (mint to minit and "lname" instead of "@lname")

Now I get the following at the DsEmployee1.Clear() (of cbo_selectedindexchange)

An unhandled exception of type 'System.NullReferenceException' occurred in WindowsApplication2.exe
Additional information: Object reference not set to an instance of an object.

But, I had fiddled with the ds, so it was now DsEmployee2 - I changed those two references and now it halts at:

lblHireDate.Text = FormatDateTime(CDate(lblHireDate.Text), DateFormat.ShortDate)

Cast from string '"' to type 'Date' is not valid
0
 
sirbountyAuthor Commented:
Hmm - and removing that line altogether (the date), doesn't flag an error, but none of the fields are populated... :'(
0
 
sirbountyAuthor Commented:
It's working! Yay! (that was much less painful than the last one).

So that I kind of understand here - it looks like, when I went to make those adjustments the 'Automatic code generator' (is that an actual name for it?) was the culprit in screwing up what I had.

That being the case, I simply had to repoint the controls to be bound to the proper dataset.
Once that was done, everything was back to 'before'.  I only had to change
lblFirstName back to lblName and then change it's binding to employee.name (instead of fname).

Thanx very much (again) Roger.  
You've been more than helpful and extremely patient.  I do appreciate your help!!
0
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.