Using DataBasics to execute a non-bo-bound stored procedure


Author
Message
Philipp Guntermann
Philipp Guntermann
StrataFrame User (249 reputation)StrataFrame User (249 reputation)StrataFrame User (249 reputation)StrataFrame User (249 reputation)StrataFrame User (249 reputation)StrataFrame User (249 reputation)StrataFrame User (249 reputation)StrataFrame User (249 reputation)StrataFrame User (249 reputation)
Group: Forum Members
Posts: 141, Visits: 263
Hi,

I am wondering if someone could provide a sample code as how I can use

DataBasics.DataSources[""].ExecuteStoredProcedure(..)

 

My sproc takes 2 varchar input parameters and returns an integer value:

@HWID VARCHAR(250),

@ComputerName VARCHAR(250),

@iKassenId int OUTPUT

 

i want to execute the sproc and get the Result integer.

Thanks !

 


Replies
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (4.8K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
I'm wondering if the problem is that you are using Return instead of Select. My understanding is that Return is used to return a status code, while you'd use Select to return a record set, which ExecuteScalar will then retrieve data from. So change:



RETURN @iKassenId




to



Select @iKassenId




and see if that works. I'm guessing that since you don't select anything, either null or DdNull.Value is being returned from execute scalar.



You might also want to check for conditions like this in code. Something like:



object result = DataBasics.DataSources[""].ExecuteStoredProcedure("spK_KassenAnmeldung", DbCommandExecutionType.ExecuteScalar, spParams);

if result != null && result != DbNull.Value

{

return (int)result;

}

else

{

// return default or throw an exception

return 0

}


Philipp Guntermann
Philipp Guntermann
StrataFrame User (249 reputation)StrataFrame User (249 reputation)StrataFrame User (249 reputation)StrataFrame User (249 reputation)StrataFrame User (249 reputation)StrataFrame User (249 reputation)StrataFrame User (249 reputation)StrataFrame User (249 reputation)StrataFrame User (249 reputation)
Group: Forum Members
Posts: 141, Visits: 263
hi,

thanks. that seems like it could be the problem. i wasnt aware of the use of select instead of return.

i will try changing it when i get back to work tommorow.

Alex Luyando
Alex Luyando
StrataFrame User (298 reputation)StrataFrame User (298 reputation)StrataFrame User (298 reputation)StrataFrame User (298 reputation)StrataFrame User (298 reputation)StrataFrame User (298 reputation)StrataFrame User (298 reputation)StrataFrame User (298 reputation)StrataFrame User (298 reputation)
Group: StrataFrame Users
Posts: 112, Visits: 1.2K
Greg McGuffey (08/26/2008)
I'm wondering if the problem is that you are using Return instead of Select. My understanding is that Return is used to return a status code, while you'd use Select to return a record set, which ExecuteScalar will then retrieve data from.




How I wish I had read this about two hours earlier! LOL



Very handy to know.. Thanks!

________________
_____/ Regards,
____/ al
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (4.8K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
LOL! Glad you found a solution to your issue though!
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Threaded View
Threaded View
Philipp Guntermann - 17 Years Ago
Philipp Guntermann - 17 Years Ago
Philipp Guntermann - 17 Years Ago
Philipp Guntermann - 17 Years Ago
Michel Levy - 17 Years Ago
Philipp Guntermann - 17 Years Ago
Michel Levy - 17 Years Ago
Dustin Taylor - 17 Years Ago
Philipp Guntermann - 17 Years Ago
Greg McGuffey - 17 Years Ago
Philipp Guntermann - 17 Years Ago
Alex Luyando - 16 Years Ago
                         LOL! Glad you found a solution to your issue though!
Greg McGuffey - 16 Years Ago
Dustin Taylor - 17 Years Ago
Philipp Guntermann - 17 Years Ago
Greg McGuffey - 17 Years Ago

Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search