Why doesn't this work?

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

    #1

    Why doesn't this work?

    Hi all,

    I get a 'input string was not in a correct format' error on the second
    line of code here. The sproc defines the '@quan5x7' as int.

    sqlCmd.Paramete rs.Add("@quan5x 7", SqlDbType.Int);
    sqlCmd.Paramete rs[21].Value = Convert.ToInt32 (cmbQuan5x7.Tex t);

    The SqlDbType.Int is equal to System.Int32 correct?

    Using C# Express and SQL 2005 Express. Thanks for any insight.

  • =?ISO-8859-1?Q?G=F6ran_Andersson?=

    #2
    Re: Why doesn't this work?

    Looch wrote:
    Hi all,
    >
    I get a 'input string was not in a correct format' error on the second
    line of code here. The sproc defines the '@quan5x7' as int.
    >
    sqlCmd.Paramete rs.Add("@quan5x 7", SqlDbType.Int);
    sqlCmd.Paramete rs[21].Value = Convert.ToInt32 (cmbQuan5x7.Tex t);
    The text of the control is a value that can not be converted to an int.
    The SqlDbType.Int is equal to System.Int32 correct?
    Yes.
    Using C# Express and SQL 2005 Express. Thanks for any insight.
    >

    --
    Göran Andersson
    _____
    Göran Anderssons privata hemsida.

    Comment

    • Tom Porterfield

      #3
      Re: Why doesn't this work?

      Looch wrote:
      Hi all,
      >
      I get a 'input string was not in a correct format' error on the second
      line of code here. The sproc defines the '@quan5x7' as int.
      >
      sqlCmd.Paramete rs.Add("@quan5x 7", SqlDbType.Int);
      sqlCmd.Paramete rs[21].Value = Convert.ToInt32 (cmbQuan5x7.Tex t);
      >
      The SqlDbType.Int is equal to System.Int32 correct?
      >
      Using C# Express and SQL 2005 Express. Thanks for any insight.
      My initial guess is that cmbQuan5x7.Text does not contain a value that
      can be converted to an int.
      --
      Tom Porterfield

      Comment

      • Morten Wennevik [C# MVP]

        #4
        Re: Why doesn't this work?

        On Wed, 18 Jul 2007 19:28:22 +0200, Looch <lucianoj2005@y ahoo.comwrote:
        Hi all,
        >
        I get a 'input string was not in a correct format' error on the second
        line of code here. The sproc defines the '@quan5x7' as int.
        >
        sqlCmd.Paramete rs.Add("@quan5x 7", SqlDbType.Int);
        sqlCmd.Paramete rs[21].Value = Convert.ToInt32 (cmbQuan5x7.Tex t);
        >
        The SqlDbType.Int is equal to System.Int32 correct?
        >
        Using C# Express and SQL 2005 Express. Thanks for any insight.
        >
        >
        I'm guessing the 21st SqlParameter isn't what you think it is, try

        sqlCmd.Paramete rs["@quan5x7"].Value = Convert.ToInt32 (cmbQuan5x7.Tex t);

        --
        Happy coding!
        Morten Wennevik [C# MVP]

        Comment

        • Jon Skeet [C# MVP]

          #5
          Re: Why doesn't this work?

          Looch <lucianoj2005@y ahoo.comwrote:
          I get a 'input string was not in a correct format' error on the second
          line of code here. The sproc defines the '@quan5x7' as int.
          >
          sqlCmd.Paramete rs.Add("@quan5x 7", SqlDbType.Int);
          sqlCmd.Paramete rs[21].Value = Convert.ToInt32 (cmbQuan5x7.Tex t);
          >
          The SqlDbType.Int is equal to System.Int32 correct?
          Well, they're not the same type - but the chances are that the problem
          is really that cmbQuan5x7.Text can't be parsed as an integer.

          --
          Jon Skeet - <skeet@pobox.co m>
          http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
          If replying to the group, please do not mail me too

          Comment

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

            #6
            Re: Why doesn't this work?

            Hi,

            "Looch" <lucianoj2005@y ahoo.comwrote in message
            news:1184779702 .811588.273120@ m37g2000prh.goo glegroups.com.. .
            Hi all,
            >
            I get a 'input string was not in a correct format' error on the second
            line of code here. The sproc defines the '@quan5x7' as int.
            >
            sqlCmd.Paramete rs.Add("@quan5x 7", SqlDbType.Int);
            sqlCmd.Paramete rs[21].Value = Convert.ToInt32 (cmbQuan5x7.Tex t);
            >
            The SqlDbType.Int is equal to System.Int32 correct?
            not the same, but you have a defined conversion.

            The problem most probably is cause cmbQuan5x7.Text is not an integer value


            Comment

            • Enkidu

              #7
              Re: Why doesn't this work?

              Morten Wennevik [C# MVP] wrote:
              On Wed, 18 Jul 2007 19:28:22 +0200, Looch <lucianoj2005@y ahoo.comwrote:
              >
              >Hi all,
              >>
              >I get a 'input string was not in a correct format' error on the second
              >line of code here. The sproc defines the '@quan5x7' as int.
              >>
              >sqlCmd.Paramet ers.Add("@quan5 x7", SqlDbType.Int);
              >sqlCmd.Paramet ers[21].Value = Convert.ToInt32 (cmbQuan5x7.Tex t);
              >>
              >The SqlDbType.Int is equal to System.Int32 correct?
              >>
              >Using C# Express and SQL 2005 Express. Thanks for any insight.
              >>
              >>
              >
              I'm guessing the 21st SqlParameter isn't what you think it is, try
              >
              sqlCmd.Paramete rs["@quan5x7"].Value = Convert.ToInt32 (cmbQuan5x7.Tex t);
              >
              Did you mean 22nd?

              Cheers,

              Cliff

              --

              Have you ever noticed that if something is advertised as 'amusing' or
              'hilarious', it usually isn't?

              Comment

              • Morten Wennevik [C# MVP]

                #8
                Re: Why doesn't this work?

                On Wed, 18 Jul 2007 23:25:39 +0200, Enkidu <enkidu.com@com .cliffp.comwrot e:
                Morten Wennevik [C# MVP] wrote:
                >On Wed, 18 Jul 2007 19:28:22 +0200, Looch <lucianoj2005@y ahoo.comwrote:
                >>
                >>Hi all,
                >>>
                >>I get a 'input string was not in a correct format' error on the second
                >>line of code here. The sproc defines the '@quan5x7' as int.
                >>>
                >>sqlCmd.Parame ters.Add("@quan 5x7", SqlDbType.Int);
                >>sqlCmd.Parame ters[21].Value = Convert.ToInt32 (cmbQuan5x7.Tex t);
                >>>
                >>The SqlDbType.Int is equal to System.Int32 correct?
                >>>
                >>Using C# Express and SQL 2005 Express. Thanks for any insight.
                >>>
                >>>
                >>
                >I'm guessing the 21st SqlParameter isn't what you think it is, try
                >>
                >sqlCmd.Paramet ers["@quan5x7"].Value = Convert.ToInt32 (cmbQuan5x7.Tex t);
                >>
                Did you mean 22nd?
                >
                Cheers,
                >
                Cliff
                >
                Ah, a bit hasty there :) Anyhow, the most likely cause for his error isprobably empty Text property or a Text property containing something other than an integer value.

                --
                Happy coding!
                Morten Wennevik [C# MVP]

                Comment

                Working...