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. command returning null value

command returning null value

Scheduled Pinned Locked Moved ASP.NET
databasesql-serversysadminhelpquestion
5 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.
  • M Offline
    M Offline
    myinstincts
    wrote on last edited by
    #1

    string connection = ConfigurationManager.AppSettings["connectionstring"]; SqlConnection con = new SqlConnection(connection); con.Open(); SqlCommand cmd = new SqlCommand("select place_name from place inner join state on place.state_id=state.state_id where state_name ='" + statedpdwnlist.SelectedItem.Value + "'", con); dr = cmd.ExecuteReader(); con.close(); I cannot figure out why the above command is returning null value eventhough it is giving the desired output whn the same command is run on sql server query analyser.Can anybody help me with this??????( statedpdwnlist.SelectedItem.Value is coming correct in the query)

    C A 2 Replies Last reply
    0
    • M myinstincts

      string connection = ConfigurationManager.AppSettings["connectionstring"]; SqlConnection con = new SqlConnection(connection); con.Open(); SqlCommand cmd = new SqlCommand("select place_name from place inner join state on place.state_id=state.state_id where state_name ='" + statedpdwnlist.SelectedItem.Value + "'", con); dr = cmd.ExecuteReader(); con.close(); I cannot figure out why the above command is returning null value eventhough it is giving the desired output whn the same command is run on sql server query analyser.Can anybody help me with this??????( statedpdwnlist.SelectedItem.Value is coming correct in the query)

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

      Have you copied the SQL in the debugger to make sure it's exactly right and works in QA ?

      Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

      A 1 Reply Last reply
      0
      • M myinstincts

        string connection = ConfigurationManager.AppSettings["connectionstring"]; SqlConnection con = new SqlConnection(connection); con.Open(); SqlCommand cmd = new SqlCommand("select place_name from place inner join state on place.state_id=state.state_id where state_name ='" + statedpdwnlist.SelectedItem.Value + "'", con); dr = cmd.ExecuteReader(); con.close(); I cannot figure out why the above command is returning null value eventhough it is giving the desired output whn the same command is run on sql server query analyser.Can anybody help me with this??????( statedpdwnlist.SelectedItem.Value is coming correct in the query)

        A Offline
        A Offline
        Abhijit Jana
        wrote on last edited by
        #3

        myinstincts wrote:

        SqlCommand cmd = new SqlCommand("select place_name from place inner join state on place.state_id=state.state_id where state_name ='" + statedpdwnlist.SelectedItem.Value + "'", con);

        Do like this :

        string S="select place_name from place inner join state on place.state_id=state.state_id where state_name ='" + statedpdwnlist.SelectedItem.Value + "'"
        SqlCommand cmd = new SqlCommand(s, con);

        Now, Put a breakpoint on String S line, check the value of S. Then put the same string on SQL Server Query window and check the result. This will clear your doubts !

        Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.

        1 Reply Last reply
        0
        • C Christian Graus

          Have you copied the SQL in the debugger to make sure it's exactly right and works in QA ?

          Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

          A Offline
          A Offline
          Abhijit Jana
          wrote on last edited by
          #4

          Sorry I didn't see your reply before I post. :doh:

          Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.

          C 1 Reply Last reply
          0
          • A Abhijit Jana

            Sorry I didn't see your reply before I post. :doh:

            Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.

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

            *grin* probably because it wasn't there and you put more time in to your reply.

            Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

            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