none
Double parameter of SQL commands causes error RRS feed

  • Question

  • Hello all,

    I am inserting some data to SQL server 2008 table. I am using

    SqlConnection connection = new SqlConnection(connectionstring)
    SqlCommand command = connection.CreateCommand();
    command.CommandText = "INSERT INTO table ([col1], [col2], ...) VALUES (@par1, @par2 ...)"
    command.Parameters.Add(new SqlParameter("@par1", variable)); ...
    command.ExecuteNonQuery();
     

    I am getting error "Must pass parameter number 15 and subsequent parameters as '@name = value'. After the form '@name = value' has been used, all subsequent parameters must be passed in the form '@name = value'."

    I catched the command using SQL profiler and discovered, that the problem is cause by one parameter type double. The double value 22,5 with "," as a decimal separator is understood as 2 values, 22 and 5, where 5 comes without parameter name.

    This is from the profiler (my insert command has been somehow transformed to call of procedure):

    exec sp_executesql N'INSERT INTO infrastructureLayer VALUES(... @Press,... @Press=22,5, ...

    What to do with it?

    Tuesday, April 27, 2010 8:13 AM

Answers

  • And I must announce that I have also found a solution. Insert

    Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

    before any db commands and that's all. It forces using decimal separator "."
    But this is a bug somewhere in .NET.

    • Marked as answer by MMMMartin Tuesday, April 27, 2010 9:00 AM
    Tuesday, April 27, 2010 9:00 AM

All replies

  • And I must announce that I have also found a solution. Insert

    Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

    before any db commands and that's all. It forces using decimal separator "."
    But this is a bug somewhere in .NET.

    • Marked as answer by MMMMartin Tuesday, April 27, 2010 9:00 AM
    Tuesday, April 27, 2010 9:00 AM
  • Specify the parameter type when adding them.
    http://erikej.blogspot.com Erik Ejlskov Jensen - Please mark as answer, if this was it.
    Thursday, April 29, 2010 6:37 PM