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
  1. Home
  2. Web Development
  3. ASP.NET
  4. conversion problem

conversion problem

Scheduled Pinned Locked Moved ASP.NET
3 Posts 3 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.
  • S Offline
    S Offline
    saravanan05
    wrote on last edited by
    #1

    hi to all Function: --------- public static int GetScalar(string query) { OdbcConnection myconnGS = new OdbcConnection(); OdbcCommand mycmdGS = new OdbcCommand(); myconnGS = DBManager.getConnection(); mycmdGS = new OdbcCommand(query, myconnGS); return mycmdGS.ExecuteScalar();--error occured this line(patriculy mycmdGS) myconnGS.Close(); } error: Cannot implicitly convert type 'object' to 'int'. An explicit conversion exists (are you missing a cast?) D:\aesweb\WebSite\Controls\MainBannerAdControl.ascx.cs 98 16 D:\aesweb\WebSite\

    Known Is Drop.Unknown Is Ocean

    S V 2 Replies Last reply
    0
    • S saravanan05

      hi to all Function: --------- public static int GetScalar(string query) { OdbcConnection myconnGS = new OdbcConnection(); OdbcCommand mycmdGS = new OdbcCommand(); myconnGS = DBManager.getConnection(); mycmdGS = new OdbcCommand(query, myconnGS); return mycmdGS.ExecuteScalar();--error occured this line(patriculy mycmdGS) myconnGS.Close(); } error: Cannot implicitly convert type 'object' to 'int'. An explicit conversion exists (are you missing a cast?) D:\aesweb\WebSite\Controls\MainBannerAdControl.ascx.cs 98 16 D:\aesweb\WebSite\

      Known Is Drop.Unknown Is Ocean

      S Offline
      S Offline
      SeMartens
      wrote on last edited by
      #2

      Well as the error message is saying, the result of an OdbcCommand.ExecuteScalar is an object. You have to cast this one to return an int. Have a look here: http://msdn.microsoft.com/en-us/library/system.data.odbc.odbccommand.executescalar.aspx And your myConnGS.Close() will never be executed. Try to improve your design here. Regards Sebastian.

      It's not a bug, it's a feature! Check out my CodeProject article Permission-by-aspect. Me in Softwareland.

      1 Reply Last reply
      0
      • S saravanan05

        hi to all Function: --------- public static int GetScalar(string query) { OdbcConnection myconnGS = new OdbcConnection(); OdbcCommand mycmdGS = new OdbcCommand(); myconnGS = DBManager.getConnection(); mycmdGS = new OdbcCommand(query, myconnGS); return mycmdGS.ExecuteScalar();--error occured this line(patriculy mycmdGS) myconnGS.Close(); } error: Cannot implicitly convert type 'object' to 'int'. An explicit conversion exists (are you missing a cast?) D:\aesweb\WebSite\Controls\MainBannerAdControl.ascx.cs 98 16 D:\aesweb\WebSite\

        Known Is Drop.Unknown Is Ocean

        V Offline
        V Offline
        vinodkrebc
        wrote on last edited by
        #3

        write the following code instead of return mycmdGS.ExecuteScalar() return (int)mycmdGS.ExecuteScalar(); I hope it will work now Thank YOu Vinod Kr. Software Engineer EBC Publishing Lucknow

        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