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. General Programming
  3. C#
  4. get value from database into a variable

get value from database into a variable

Scheduled Pinned Locked Moved C#
databasehelpquestion
4 Posts 4 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.
  • N Offline
    N Offline
    Nekshan
    wrote on last edited by
    #1

    Will this get value dashboardid from table into variable 'str'? int str = "select dashboardid from dashboardlogin where userid=101"; dashboardid is 'int' type in database. but i have error if i use this: Cannot implicitly convert type 'string' to 'int'. do i need to add any other code also for getting its data into variable 'str'? plz reply thank you. nekshan.

    B C A 3 Replies Last reply
    0
    • N Nekshan

      Will this get value dashboardid from table into variable 'str'? int str = "select dashboardid from dashboardlogin where userid=101"; dashboardid is 'int' type in database. but i have error if i use this: Cannot implicitly convert type 'string' to 'int'. do i need to add any other code also for getting its data into variable 'str'? plz reply thank you. nekshan.

      B Offline
      B Offline
      blue_arc
      wrote on last edited by
      #2

      hey this is wrong , either u write a stored procedured which will return a parameters from stored procedures.. or execute the query. get the result set in to datatable and get ur value from there.

      Ravi Kant Srivastava (System Analyst) HandsOn Technology & Engineering Gurgaon (India) e-mail:ravikant@hte.co.in

      1 Reply Last reply
      0
      • N Nekshan

        Will this get value dashboardid from table into variable 'str'? int str = "select dashboardid from dashboardlogin where userid=101"; dashboardid is 'int' type in database. but i have error if i use this: Cannot implicitly convert type 'string' to 'int'. do i need to add any other code also for getting its data into variable 'str'? plz reply thank you. nekshan.

        C Offline
        C Offline
        Corinna John
        wrote on last edited by
        #3

        Your statement getsthe query string into the string variable str. The compiler error occurs, because str is declared as an int. If you want to use LINQ to query the datasource, try this article: http://www.codeproject.com/useritems/SudokuSolver.asp[^] Otherwise you have to connect to the database and query it with an SqlCommand: using (SqlCommand selectCommand = new SqlCommand("select dashboardid from dashboardlogin where userid=101", connection)) { object objResult = selectCommand.ExecuteScalar(); if (objResult != null) { int str = (int)objResult; } }

        ____________________________________ There is no proof for this sentence.

        1 Reply Last reply
        0
        • N Nekshan

          Will this get value dashboardid from table into variable 'str'? int str = "select dashboardid from dashboardlogin where userid=101"; dashboardid is 'int' type in database. but i have error if i use this: Cannot implicitly convert type 'string' to 'int'. do i need to add any other code also for getting its data into variable 'str'? plz reply thank you. nekshan.

          A Offline
          A Offline
          aSarafian
          wrote on last edited by
          #4

          You got it all wrong. Please read a database tutorial. Just a hint. Someone must execute the desired sql command , don't you think? Its just as you have written int a="Hello World"; the you just happen to have for text an a sql command. Read the db tutorial.

          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