Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. cannot implicitly convert type 'int' to 'string'

cannot implicitly convert type 'int' to 'string'

Scheduled Pinned Locked Moved C#
help
6 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    twistz
    wrote on last edited by
    #1

    public string deleteDB(string strSelect) { try { cmd.Connection = objConn; cmd.CommandText = strSelect; cmd.ExecuteScalar(); } catch (SqlException eException) { Console.Write("Error in connection : " + eException.Message); return -10; //return strSelect; } }

    C H S 3 Replies Last reply
    0
    • T twistz

      public string deleteDB(string strSelect) { try { cmd.Connection = objConn; cmd.CommandText = strSelect; cmd.ExecuteScalar(); } catch (SqlException eException) { Console.Write("Error in connection : " + eException.Message); return -10; //return strSelect; } }

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Well, did you read the error message ? Your function returns a string, and you're tring to return -10. Which is both stupid ( what does -10 mean ? ) and illegal ( an int is not a number ). The logical thing to return here is probably a bool. Why bother returning the string that was passed in ? Where does strSelect come from ? This looks silly to me from the get go. You're just taking SQL as a string and calling it, this should not exist at all, but if it did, it should have a generic name, there is not guarentee it will delete anything. There is so much wrong with this, you should probably go back to basics and do some reading. But, to fix the problem at hand, read your error messages and believe them. You said you were returning a string. The compiler won't turn an int to a string, so return a string, or change the return type. And, return something when the code doesn't blow up, too.

      Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

      L 1 Reply Last reply
      0
      • T twistz

        public string deleteDB(string strSelect) { try { cmd.Connection = objConn; cmd.CommandText = strSelect; cmd.ExecuteScalar(); } catch (SqlException eException) { Console.Write("Error in connection : " + eException.Message); return -10; //return strSelect; } }

        H Offline
        H Offline
        Harvey Saayman
        wrote on last edited by
        #3

        your trying to return an int in a method that needs to return a string... youl have to return "-10" in your catch block... and use PRE tags when posting code please

        Harvey Saayman - South Africa Junior Developer .Net, C#, SQL

        you.suck = (you.passion != Programming)

        1 Reply Last reply
        0
        • C Christian Graus

          Well, did you read the error message ? Your function returns a string, and you're tring to return -10. Which is both stupid ( what does -10 mean ? ) and illegal ( an int is not a number ). The logical thing to return here is probably a bool. Why bother returning the string that was passed in ? Where does strSelect come from ? This looks silly to me from the get go. You're just taking SQL as a string and calling it, this should not exist at all, but if it did, it should have a generic name, there is not guarentee it will delete anything. There is so much wrong with this, you should probably go back to basics and do some reading. But, to fix the problem at hand, read your error messages and believe them. You said you were returning a string. The compiler won't turn an int to a string, so return a string, or change the return type. And, return something when the code doesn't blow up, too.

          Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

          L Offline
          L Offline
          leppie
          wrote on last edited by
          #4

          Christian Graus wrote:

          an int is not a number

          You mean string ;P

          xacc.ide - now with TabsToSpaces support
          IronScheme - 1.0 alpha 4a out now (29 May 2008)

          C 1 Reply Last reply
          0
          • T twistz

            public string deleteDB(string strSelect) { try { cmd.Connection = objConn; cmd.CommandText = strSelect; cmd.ExecuteScalar(); } catch (SqlException eException) { Console.Write("Error in connection : " + eException.Message); return -10; //return strSelect; } }

            S Offline
            S Offline
            SteveNY
            wrote on last edited by
            #5

            -10 is a int not a string

            1 Reply Last reply
            0
            • L leppie

              Christian Graus wrote:

              an int is not a number

              You mean string ;P

              xacc.ide - now with TabsToSpaces support
              IronScheme - 1.0 alpha 4a out now (29 May 2008)

              C Offline
              C Offline
              Christian Graus
              wrote on last edited by
              #6

              *sigh* yes, I did...

              Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups