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. Access single executescalar value from dataset?

Access single executescalar value from dataset?

Scheduled Pinned Locked Moved C#
question
10 Posts 2 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
    tkrn
    wrote on last edited by
    #1

    this.presetTableAdapter.ExistPreset(txtToolNumber.Text); I am trying to access a single value from a dataset, this is how i am calling it, how can i access the value from that dataset? It either outputs a 1 or a 0, pretty straight forward right?

    W 1 Reply Last reply
    0
    • T tkrn

      this.presetTableAdapter.ExistPreset(txtToolNumber.Text); I am trying to access a single value from a dataset, this is how i am calling it, how can i access the value from that dataset? It either outputs a 1 or a 0, pretty straight forward right?

      W Offline
      W Offline
      Wendelius
      wrote on last edited by
      #2

      ExistPreset doesn't seem to be framework's method. If this is true, what's the implementation?

      T 1 Reply Last reply
      0
      • W Wendelius

        ExistPreset doesn't seem to be framework's method. If this is true, what's the implementation?

        T Offline
        T Offline
        tkrn
        wrote on last edited by
        #3

        that is from a method from the tableadapater/dataset designer. that is stored procedure that returns a zero or a one. I tried what is followed here but it does not work, http://msdn.microsoft.com/en-us/library/37hwc7kt.aspx[^]

        W 1 Reply Last reply
        0
        • T tkrn

          that is from a method from the tableadapater/dataset designer. that is stored procedure that returns a zero or a one. I tried what is followed here but it does not work, http://msdn.microsoft.com/en-us/library/37hwc7kt.aspx[^]

          W Offline
          W Offline
          Wendelius
          wrote on last edited by
          #4

          Ok. In your post you don't assign the return value to any variable. Is this only missing from the post? You could use following steps to find out the problem - execute the procedure directly against the databse in Query window, see that it works - check the properties of the TableAdapter, everything as it should be - debug through ExistPreset-method and observe the values in variables, everything as it should be - use plain SqlCommand to execute the procedure and see what it returns

          T 1 Reply Last reply
          0
          • W Wendelius

            Ok. In your post you don't assign the return value to any variable. Is this only missing from the post? You could use following steps to find out the problem - execute the procedure directly against the databse in Query window, see that it works - check the properties of the TableAdapter, everything as it should be - debug through ExistPreset-method and observe the values in variables, everything as it should be - use plain SqlCommand to execute the procedure and see what it returns

            T Offline
            T Offline
            tkrn
            wrote on last edited by
            #5

            It is indeed removed from the post. int returnValue = (int)(this.presetTableAdapter.ExistPreset(txtToolNumber.Text)); The error from the stack is, "Object reference not set to an instance of an object." which i know it could mean a million and a half things. presetTableAdapter is publicly accessible table adapter, ExistPreset exists and is correct. MSSql outputs a 1 or 0 as it should. txtToolNumber.Text has a value. ::bashes head against monitor:: Mika, thanks for your help

            W 1 Reply Last reply
            0
            • T tkrn

              It is indeed removed from the post. int returnValue = (int)(this.presetTableAdapter.ExistPreset(txtToolNumber.Text)); The error from the stack is, "Object reference not set to an instance of an object." which i know it could mean a million and a half things. presetTableAdapter is publicly accessible table adapter, ExistPreset exists and is correct. MSSql outputs a 1 or 0 as it should. txtToolNumber.Text has a value. ::bashes head against monitor:: Mika, thanks for your help

              W Offline
              W Offline
              Wendelius
              wrote on last edited by
              #6

              So you got it solved?

              T 1 Reply Last reply
              0
              • W Wendelius

                So you got it solved?

                T Offline
                T Offline
                tkrn
                wrote on last edited by
                #7

                Negative.

                W 1 Reply Last reply
                0
                • T tkrn

                  Negative.

                  W Offline
                  W Offline
                  Wendelius
                  wrote on last edited by
                  #8

                  Okay, Since you get an exception, you should be able to see the source from the stack. You're right, it can be any class that is not instantiated, but stack trace should give you a good picture what class is causing the problem. Also if you define the debugger to stop on exceptions, you should get to the actual location where the exception is occuring, where you can use QuickWatch to see which object is null. When using debugger, remember that if the dataset definition is created by Visual Studio, it most propably has DebuggerStepThrough-attribute defined. Comment that out and you can debug inside generated code

                  T 1 Reply Last reply
                  0
                  • W Wendelius

                    Okay, Since you get an exception, you should be able to see the source from the stack. You're right, it can be any class that is not instantiated, but stack trace should give you a good picture what class is causing the problem. Also if you define the debugger to stop on exceptions, you should get to the actual location where the exception is occuring, where you can use QuickWatch to see which object is null. When using debugger, remember that if the dataset definition is created by Visual Studio, it most propably has DebuggerStepThrough-attribute defined. Comment that out and you can debug inside generated code

                    T Offline
                    T Offline
                    tkrn
                    wrote on last edited by
                    #9

                    Thats the thing, the error occurs at int returnValue = (int)(this.presetTableAdapter.ExistPreset(txtToolNumber.Text));

                    W 1 Reply Last reply
                    0
                    • T tkrn

                      Thats the thing, the error occurs at int returnValue = (int)(this.presetTableAdapter.ExistPreset(txtToolNumber.Text));

                      W Offline
                      W Offline
                      Wendelius
                      wrote on last edited by
                      #10

                      Possible reasons for "Object reference not set to an instance of an object." on that line are: - this = null (not likely) - this.tableAdapter = null, is it? - txtToolNumber = null, is it? - return value of (this.presetTableAdapter.ExistPreset(txtToolNumber.Text)) = null (you can see this by debugging inside the method). If none of those are null the problem is in my understanding inside ExistPreset-method, which (I presume) is genereted by VS, but still debuggable and observable (you can see this by right clicking on the method and selecting go to definition).

                      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