Error in parameter constructor name ObjectParameter C #

1

When I pass a string variable to the ObjetParameter parameter it gives the following error.

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

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

Additional information: The specified parameter name 'DESCRIPTION' 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 you have a problem with Culture? but the constructor of the object does not provide put Culture.

    
asked by anonymous 23.06.2017 / 21:03

1 answer

2

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

Remove another character from the end of the string that will work.

string nomeParameter = sql.Substring(startPosition, stopPosition - startPosition + 1);
ObjectParameter parameter = new ObjectParameter(nomeParameter, parameters[contador]);
    
23.06.2017 / 21:07