SQLClient Parameter Bug?

  • Thread starter Thread starter bob
  • Start date Start date
B

bob

Hi,
Is this a bug?
SqlClient Parameters collection
Prior to the following snippet a set of parameters were declared and
added to the parameters collection.
The parameter values I originally assigned using the syntax in the
SECOND line of code.

The code failed on the first line when it was written in the second
line syntax.with

'this Parameter collection does not contain parameter 'pmyID''

So I altered toaddress the parameter directly and the line executes
ok.


given that intellisense allows you to construct the second line syntax
is there a bug here?

thanks
Bob

pmyId.Value = en.Current.ID.ToString(); //This line works
mycmd.Parameters["pmyId"].Value = en.Current.ID.ToString() //This
line fails
 
pmyId.Value = en.Current.ID.ToString(); //This line works
mycmd.Parameters["pmyId"].Value = en.Current.ID.ToString() //This
line fails

The line that fails should take in the indexer the name of the parameter,
which probably doesn't match the name of the variable that holds it. That
is, you have to use Parameters["@MyId"] instead of Parameters["pmyId"].
 
Hi Alberto,
Thanks for that.
regards
bob
pmyId.Value = en.Current.ID.ToString(); //This line works
mycmd.Parameters["pmyId"].Value = en.Current.ID.ToString() //This
line fails

The line that fails should take in the indexer the name of the parameter,
which probably doesn't match the name of the variable that holds it. That
is, you have to use Parameters["@MyId"] instead of Parameters["pmyId"].
 

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

Back
Top