?
Solved

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

Posted on 2006-05-17
8
Medium Priority
?
1,318 Views
Last Modified: 2010-05-18
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>
0
Comment
Question by:sirbounty
  • 5
  • 3
8 Comments
 
LVL 34

Expert Comment

by:Sancler
ID: 16700576
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
 
LVL 67

Author Comment

by:sirbounty
ID: 16700727
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
 
LVL 67

Author Comment

by:sirbounty
ID: 16700741
0
Industry Leaders: 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!

 
LVL 34

Expert Comment

by:Sancler
ID: 16700986
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
 
LVL 67

Author Comment

by:sirbounty
ID: 16701167
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
 
LVL 67

Author Comment

by:sirbounty
ID: 16701178
Hmm - and removing that line altogether (the date), doesn't flag an error, but none of the fields are populated... :'(
0
 
LVL 34

Accepted Solution

by:
Sancler earned 2000 total points
ID: 16702427
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
 
LVL 67

Author Comment

by:sirbounty
ID: 16703164
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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question