Error Input string was not in a correct format

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jose Oliver

    #1

    Error Input string was not in a correct format

    I am a bit baffled on this error. A windows app written in C# is
    attempting to execute the following query:

    SELECT *
    FROM Employee
    WHERE (Name LIKE '%' + @PARAM1 + '%') AND (Name LIKE '%' + @PARAM2
    + '%') AND (Company LIKE '%' + @PARAM3 + '%')

    I am getting the following error - "Input string was not in a correct
    format."

  • =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=

    #2
    RE: Error Input string was not in a correct format

    Jose,
    I'm not sure this is really a C# language group question, but--
    The SQL statement you show would be fine if it was inside a stored procedure
    and the @PARAMxx parameter variables were sproc input parameters.

    However if this is, instead, an inline string concatenation in a block of C#
    code, it is very wrong. You should be using a parameterized query in which
    case it would look more like the following:

    string strSQL=@"SELECT * FROM Employee WHERE (Name LIKE '%' + @PARAM1 + '%')
    AND (Name LIKE '%' + @PARAM2 + '%') AND (Company LIKE '%' + @PARAM3 + '%')"

    then,
    cmd.Parameters. AddWithValue("@ PARAM1", txtBoxParam1.Te xt ); // etc.

    Hope that helps.

    -- Peter

    unBlog: http://petesbloggerama.blogspot.com
    BlogMetaFinder: http://www.blogmetafinder.com



    "Jose Oliver" wrote:
    I am a bit baffled on this error. A windows app written in C# is
    attempting to execute the following query:
    >
    SELECT *
    FROM Employee
    WHERE (Name LIKE '%' + @PARAM1 + '%') AND (Name LIKE '%' + @PARAM2
    + '%') AND (Company LIKE '%' + @PARAM3 + '%')
    >
    I am getting the following error - "Input string was not in a correct
    format."
    >
    >

    Comment

    • Ignacio Machin \( .NET/ C# MVP \)

      #3
      Re: Error Input string was not in a correct format

      Hi,

      Please clarify if this is ni C# or the actual query being executed in SQL

      If you are concatenating the values in C# maybe you have a ' character in
      one of the parameters.

      In any case post the piece of code (C#) where you are getting the error.

      --
      Ignacio Machin
      The #1 Warehouse Management System & Direct Store Delivery Software (DSD) for QuickBooks & ERP Systems – LaceUp Solutions

      Mobile & warehouse Solutions.
      "Jose Oliver" <jose_oliver@ho tmail.comwrote in message
      news:1194640012 .274576.182190@ 22g2000hsm.goog legroups.com...
      >I am a bit baffled on this error. A windows app written in C# is
      attempting to execute the following query:
      >
      SELECT *
      FROM Employee
      WHERE (Name LIKE '%' + @PARAM1 + '%') AND (Name LIKE '%' + @PARAM2
      + '%') AND (Company LIKE '%' + @PARAM3 + '%')
      >
      I am getting the following error - "Input string was not in a correct
      format."
      >

      Comment

      Working...