This is a migrated thread and some comments may be shown as answers.

[Solved] Getting the value from an SP which returns one value

1 Answer 68 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
sitefinitysteve
Top achievements
Rank 2
Iron
Iron
Veteran
sitefinitysteve asked on 08 Sep 2010, 06:13 PM
My SP calls over to another DB to return a username string...in a single line of code how can I just extract that value to display?

1 Answer, 1 is accepted

Sort by
0
Serge
Telerik team
answered on 09 Sep 2010, 03:46 PM
Hello Steve,

In this scenario you can use an output parameter for retrieving this value. More information on how to handle output parameters with OpenAccess Classic you can find in this help article. If you are using the new domain model however, you will need to do a small modification of the generated code.

If you for example have reverse mapped a Northwind database with the domain model in you context class you will have a method for each procedure. Lets have a look at this one: 

public object[] SalesByCategory(string categoryName, string ordYear)
{
    SqlParameter parameterCategoryName = new SqlParameter("CategoryName", OpenAccessType.Varchar);
    SqlParameter parameterOrdYear = new SqlParameter("OrdYear", OpenAccessType.Varchar);
 
    List<SqlParameter> sqlParameters = new List<SqlParameter>()
    {
        parameterCategoryName, parameterOrdYear
    };
     
    object[] queryResult = this.ExecuteStoredProcedure<object>("'SalesByCategory' ?,?", sqlParameters ,categoryName, ordYear); 
    return queryResult;
}


If say the CategoryName parameter was an out parameter this would not work, as a matter of fact there is a small glitch in the code generation of the context class that we have fixed but is not released. What we would need to do to make it work is copy paste this method into a partial class of the context class and modify the declaration of the parameterCategoryName to : 

SqlParameter parameterCategoryName = new SqlParameter("CategoryName", OpenAccessType.Varchar, ParameterMode.Out);

While this will work, it seems rather troublesome as you need to modify both your stored procedure and code. Unfortunately there is no simple way of return a single value from a stored procedure. 

Maybe retrieving the QueryResult and parsing it by hand is the better choice here. 

I do hope this helps.

Greetings,
Serge
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
General Discussions
Asked by
sitefinitysteve
Top achievements
Rank 2
Iron
Iron
Veteran
Answers by
Serge
Telerik team
Share this question
or