Access single executescalar value from dataset?
-
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?
-
ExistPreset doesn't seem to be framework's method. If this is true, what's the implementation?
-
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[^]
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
-
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
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
-
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
-
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
-
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
-
Thats the thing, the error occurs at
int returnValue = (int)(this.presetTableAdapter.ExistPreset(txtToolNumber.Text));
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).