Error in constructor name parameter Objectparameter C#

Asked

Viewed 36 times

1

When I pass a string variable to the Objetparameter parameter of the following error.

   string nomeParameter = sql.Substring(startPosition, stopPosition - startPosition);

   ObjectParameter parameter = new ObjectParameter(nomeParameter, parameters[contador]);

Additional information: The specified Parameter name 'DESCRICAO ' is not Valid. Parameter Names must Begin with a Letter and can only contain Letters, Numbers, and underscores.

If you pass the parameter as below, the error does not occur:

   ObjectParameter parameter = new ObjectParameter("DESCRICAO", parameters[contador]);

Would it have any problem with Culture? but the object builder not provide put to Culture.

1 answer

2


I have no idea what you’re doing, but it’s pretty clear from the description of the error, that the problem is caused by the space at the end of the string.

Remove one more character from the end of string that will work.

string nomeParameter = sql.Substring(startPosition, stopPosition - startPosition + 1);
ObjectParameter parameter = new ObjectParameter(nomeParameter, parameters[contador]);
  • It really was that friend, I put the Trim and it worked out, thank you very much.

  • I didn’t notice that.. =(

Browser other questions tagged

You are not signed in. Login or sign up in order to post.