Skip to main content

How does one determine whether the SmartObjectClientServer.ExecuteScalar method actually returns valid data when SmartObject data is loaded from the SmartBox?  The problem that I am trying to solve is to detect the case when the requested SmartObject hasn't yet been created in the SmartBox.  To illustrate this with a more concrete example, I have code that looks very similar to that of the following post...

http://k2underground.com/forums/permalink/18568/18574/ShowThread.aspx#18574

icon-quote.gifOlafWagner:

//Call the Load Method
soEmployee.MethodToExecute = "Load";
soEmployee.Propertiese"ID"].Value = "1234";
soServer.ExecuteScalar(soEmployee);




Now, suppose the employee with ID 1234 is not yet created, how can I detect this condition after the ExecuteScalar statement in a generic way?  Even when the SmartObject does not exist, the ExecuteScalar method returns without throwing any exception, and the input parameter and returned value seems to be the same object.  But how do I know that the SmartObject that is returned contains data of an existing SmartObject (with default values) or if the object still needs to be created?

 

Thanks. 

In case anybody else is interested to know, this cannot easily be done with the current version of BlackPearl.  But there is a workaround for this requirement.  If the object to be loaded doesn't exist when loaded, all property values that haven't been populated before the ExecuteScalar call would be null when the call returns.  You can test for this condition and this would signal the possibility that the object might in fact not exist.  Then, double check with a call to the "GetList" method, and if you get back zero items, then you're sure the object doesn't yet exist.

I'm actually dealing with something similar right now that has been causing me a lot of grief.  I'm using the SqlDataSource to connect to a SmartObject and using a FormView on my page.  Well, the Read method on my SmartObject is returning an empty record when I pass in a key that I know doesn't exist whereas the List method will not return any records at all (what I was expecting).  I'm not sure if this is a bug or expected behavior.  I just looked through the How-To video (#5) and he uses the List method in the Select tab.  Since I only wanted to return a single record (if it existed), I was using the Read method.


Reply