Using Dapper by stored procedureInsert results of a stored procedure into a temporary tableFunction vs. Stored Procedure in SQL ServerIs there a way to call a stored procedure with Dapper?Dapper throwing invalid cast exception when using strongly-typed query parameters with Sybase ASEHow to return null from a Dapper query rather than default(T)?Search text in stored procedure in SQL ServerDapper Stored procedure and ViewDynamic results using dapper in mvcDapper Stored Procedures Zero ConversionHow to use Dapper asynchronously with multiple stored procedure calls?
Is multiplication of real numbers uniquely defined as being distributive over addition?
Is TA-ing worth the opportunity cost?
Infeasibility in mathematical optimization models
Tikzcd pullback square issue
Is there a way to create a report for the failed entries while calling REST API
In Pokémon Go, why does one of my Pikachu have an option to evolve, but another one doesn't?
Does the Shapechange spell allow one to use Innate Spellcasting of the creature they turned into?
Why is there a need to prevent a racist, sexist, or otherwise bigoted vendor from discriminating who they sell to?
What is the idiomatic way of saying “he is ticklish under armpits”?
As a 16 year old, how can I keep my money safe from my mother?
Does this smartphone photo show Mars just below the Sun?
Does the United States guarantee any unique freedoms?
How does The Fools Guild make its money?
Look mom! I made my own (Base 10) numeral system!
In a topological space if there exists a loop that cannot be contracted to a point does there exist a simple loop that cannot be contracted also?
A question about 'reptile and volatiles' to describe creatures
How do we avoid CI-driven development...?
In the movie Harry Potter and the Order or the Phoenix, why didn't Mr. Filch succeed to open the Room of Requirement if it's what he needed?
Ex-contractor published company source code and secrets online
Can you use the Fly spell to move underwater at a speed of 60 feet?
Acceptable to cut steak before searing?
How to identify the wires on the dimmer to convert it to Conventional on/off switch
How do I calculate the difference in lens reach between a superzoom compact and a DSLR zoom lens?
Is there a loss of quality when converting RGB to HEX?
Using Dapper by stored procedure
Insert results of a stored procedure into a temporary tableFunction vs. Stored Procedure in SQL ServerIs there a way to call a stored procedure with Dapper?Dapper throwing invalid cast exception when using strongly-typed query parameters with Sybase ASEHow to return null from a Dapper query rather than default(T)?Search text in stored procedure in SQL ServerDapper Stored procedure and ViewDynamic results using dapper in mvcDapper Stored Procedures Zero ConversionHow to use Dapper asynchronously with multiple stored procedure calls?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I am working on asp.net core by using dapper ORM.I want to execute stored procedure in dapper and get the result in boolean value.How i can achieve this?
Actually, In stored procedure , i am returning 0 or 1,but when response come back in code, then the result have -1, i am confused, i am returning just 0 or 1.
using (var connection = new SqlConnection(connectionString))
// Create User Connection
var queryParameters1 = new DynamicParameters();
queryParameters1.Add("@ConnectionId", connectionId);
queryParameters1.Add("@UserTokenId", tokenResult?.Id);
response = await connection.ExecuteAsync(
"Proc_CreateUserConnection",
queryParameters1,
commandType: CommandType.StoredProcedure);
I want to get the stored procedure output in boolean value or in the form of 0 or 1.
c# stored-procedures asp.net-core dapper
|
show 1 more comment
I am working on asp.net core by using dapper ORM.I want to execute stored procedure in dapper and get the result in boolean value.How i can achieve this?
Actually, In stored procedure , i am returning 0 or 1,but when response come back in code, then the result have -1, i am confused, i am returning just 0 or 1.
using (var connection = new SqlConnection(connectionString))
// Create User Connection
var queryParameters1 = new DynamicParameters();
queryParameters1.Add("@ConnectionId", connectionId);
queryParameters1.Add("@UserTokenId", tokenResult?.Id);
response = await connection.ExecuteAsync(
"Proc_CreateUserConnection",
queryParameters1,
commandType: CommandType.StoredProcedure);
I want to get the stored procedure output in boolean value or in the form of 0 or 1.
c# stored-procedures asp.net-core dapper
Try changingExecuteAsync(..)
toExecuteScalarAsync<bool>(...)
– Simply Ged
Mar 27 at 6:58
How do you return the result from the stored procedure, with areturn
statement or by using aselect
?
– Dirk
Mar 27 at 7:02
Drik, I am using select statement in stored procedure
– Ali
Mar 27 at 7:12
@Ali in this case theExecuteScalarAsync
method proposed in the answers will work. For return values this works a bit different (using a parameter withParameterDirection.ReturnValue
)
– Dirk
Mar 27 at 7:41
The point ultimately here is that the result ofExecuteAsync
is the same as the result ofDbCommand.ExecuteNonQueryAsync
- and the integer result of that is not anything to do with anything youselect
orreturn
- it is a separate thing. If you want toselect
a result, you're closer toDbCommand.ExecuteScalarAsync
, which dapper makes available via an extension method of the same name
– Marc Gravell♦
Mar 27 at 8:25
|
show 1 more comment
I am working on asp.net core by using dapper ORM.I want to execute stored procedure in dapper and get the result in boolean value.How i can achieve this?
Actually, In stored procedure , i am returning 0 or 1,but when response come back in code, then the result have -1, i am confused, i am returning just 0 or 1.
using (var connection = new SqlConnection(connectionString))
// Create User Connection
var queryParameters1 = new DynamicParameters();
queryParameters1.Add("@ConnectionId", connectionId);
queryParameters1.Add("@UserTokenId", tokenResult?.Id);
response = await connection.ExecuteAsync(
"Proc_CreateUserConnection",
queryParameters1,
commandType: CommandType.StoredProcedure);
I want to get the stored procedure output in boolean value or in the form of 0 or 1.
c# stored-procedures asp.net-core dapper
I am working on asp.net core by using dapper ORM.I want to execute stored procedure in dapper and get the result in boolean value.How i can achieve this?
Actually, In stored procedure , i am returning 0 or 1,but when response come back in code, then the result have -1, i am confused, i am returning just 0 or 1.
using (var connection = new SqlConnection(connectionString))
// Create User Connection
var queryParameters1 = new DynamicParameters();
queryParameters1.Add("@ConnectionId", connectionId);
queryParameters1.Add("@UserTokenId", tokenResult?.Id);
response = await connection.ExecuteAsync(
"Proc_CreateUserConnection",
queryParameters1,
commandType: CommandType.StoredProcedure);
I want to get the stored procedure output in boolean value or in the form of 0 or 1.
c# stored-procedures asp.net-core dapper
c# stored-procedures asp.net-core dapper
asked Mar 27 at 6:51
AliAli
328 bronze badges
328 bronze badges
Try changingExecuteAsync(..)
toExecuteScalarAsync<bool>(...)
– Simply Ged
Mar 27 at 6:58
How do you return the result from the stored procedure, with areturn
statement or by using aselect
?
– Dirk
Mar 27 at 7:02
Drik, I am using select statement in stored procedure
– Ali
Mar 27 at 7:12
@Ali in this case theExecuteScalarAsync
method proposed in the answers will work. For return values this works a bit different (using a parameter withParameterDirection.ReturnValue
)
– Dirk
Mar 27 at 7:41
The point ultimately here is that the result ofExecuteAsync
is the same as the result ofDbCommand.ExecuteNonQueryAsync
- and the integer result of that is not anything to do with anything youselect
orreturn
- it is a separate thing. If you want toselect
a result, you're closer toDbCommand.ExecuteScalarAsync
, which dapper makes available via an extension method of the same name
– Marc Gravell♦
Mar 27 at 8:25
|
show 1 more comment
Try changingExecuteAsync(..)
toExecuteScalarAsync<bool>(...)
– Simply Ged
Mar 27 at 6:58
How do you return the result from the stored procedure, with areturn
statement or by using aselect
?
– Dirk
Mar 27 at 7:02
Drik, I am using select statement in stored procedure
– Ali
Mar 27 at 7:12
@Ali in this case theExecuteScalarAsync
method proposed in the answers will work. For return values this works a bit different (using a parameter withParameterDirection.ReturnValue
)
– Dirk
Mar 27 at 7:41
The point ultimately here is that the result ofExecuteAsync
is the same as the result ofDbCommand.ExecuteNonQueryAsync
- and the integer result of that is not anything to do with anything youselect
orreturn
- it is a separate thing. If you want toselect
a result, you're closer toDbCommand.ExecuteScalarAsync
, which dapper makes available via an extension method of the same name
– Marc Gravell♦
Mar 27 at 8:25
Try changing
ExecuteAsync(..)
to ExecuteScalarAsync<bool>(...)
– Simply Ged
Mar 27 at 6:58
Try changing
ExecuteAsync(..)
to ExecuteScalarAsync<bool>(...)
– Simply Ged
Mar 27 at 6:58
How do you return the result from the stored procedure, with a
return
statement or by using a select
?– Dirk
Mar 27 at 7:02
How do you return the result from the stored procedure, with a
return
statement or by using a select
?– Dirk
Mar 27 at 7:02
Drik, I am using select statement in stored procedure
– Ali
Mar 27 at 7:12
Drik, I am using select statement in stored procedure
– Ali
Mar 27 at 7:12
@Ali in this case the
ExecuteScalarAsync
method proposed in the answers will work. For return values this works a bit different (using a parameter with ParameterDirection.ReturnValue
)– Dirk
Mar 27 at 7:41
@Ali in this case the
ExecuteScalarAsync
method proposed in the answers will work. For return values this works a bit different (using a parameter with ParameterDirection.ReturnValue
)– Dirk
Mar 27 at 7:41
The point ultimately here is that the result of
ExecuteAsync
is the same as the result of DbCommand.ExecuteNonQueryAsync
- and the integer result of that is not anything to do with anything you select
or return
- it is a separate thing. If you want to select
a result, you're closer to DbCommand.ExecuteScalarAsync
, which dapper makes available via an extension method of the same name– Marc Gravell♦
Mar 27 at 8:25
The point ultimately here is that the result of
ExecuteAsync
is the same as the result of DbCommand.ExecuteNonQueryAsync
- and the integer result of that is not anything to do with anything you select
or return
- it is a separate thing. If you want to select
a result, you're closer to DbCommand.ExecuteScalarAsync
, which dapper makes available via an extension method of the same name– Marc Gravell♦
Mar 27 at 8:25
|
show 1 more comment
2 Answers
2
active
oldest
votes
I would just like to expand on this a little.
In this instance, you are returning a bool value which means its a single result. The best way to capture single results is using a scalar. This will ensure that only one value is returned and accessible by our code (as Deepankshee and others have already mentioned).
You should ensure that you issue a select command which will only ever return one result (otherwise it will fail) at the end of your stored procedure.
Then in your c# code you need to call:
var result = await conn.ExecuteScalarAsync<T>("Your procedure", new arguments ,
commandType: CommandType.StoredProcedure);
Please note as well that you should await
on this so we don't block the thread.
add a comment |
you can use ExecuteScalarAsync() instead of ExecuteAsync().Because it return a single value. when you will use select statement in SP
hope this works
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55371357%2fusing-dapper-by-stored-procedure%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
I would just like to expand on this a little.
In this instance, you are returning a bool value which means its a single result. The best way to capture single results is using a scalar. This will ensure that only one value is returned and accessible by our code (as Deepankshee and others have already mentioned).
You should ensure that you issue a select command which will only ever return one result (otherwise it will fail) at the end of your stored procedure.
Then in your c# code you need to call:
var result = await conn.ExecuteScalarAsync<T>("Your procedure", new arguments ,
commandType: CommandType.StoredProcedure);
Please note as well that you should await
on this so we don't block the thread.
add a comment |
I would just like to expand on this a little.
In this instance, you are returning a bool value which means its a single result. The best way to capture single results is using a scalar. This will ensure that only one value is returned and accessible by our code (as Deepankshee and others have already mentioned).
You should ensure that you issue a select command which will only ever return one result (otherwise it will fail) at the end of your stored procedure.
Then in your c# code you need to call:
var result = await conn.ExecuteScalarAsync<T>("Your procedure", new arguments ,
commandType: CommandType.StoredProcedure);
Please note as well that you should await
on this so we don't block the thread.
add a comment |
I would just like to expand on this a little.
In this instance, you are returning a bool value which means its a single result. The best way to capture single results is using a scalar. This will ensure that only one value is returned and accessible by our code (as Deepankshee and others have already mentioned).
You should ensure that you issue a select command which will only ever return one result (otherwise it will fail) at the end of your stored procedure.
Then in your c# code you need to call:
var result = await conn.ExecuteScalarAsync<T>("Your procedure", new arguments ,
commandType: CommandType.StoredProcedure);
Please note as well that you should await
on this so we don't block the thread.
I would just like to expand on this a little.
In this instance, you are returning a bool value which means its a single result. The best way to capture single results is using a scalar. This will ensure that only one value is returned and accessible by our code (as Deepankshee and others have already mentioned).
You should ensure that you issue a select command which will only ever return one result (otherwise it will fail) at the end of your stored procedure.
Then in your c# code you need to call:
var result = await conn.ExecuteScalarAsync<T>("Your procedure", new arguments ,
commandType: CommandType.StoredProcedure);
Please note as well that you should await
on this so we don't block the thread.
edited Mar 27 at 8:22
Marc Gravell♦
815k206 gold badges2213 silver badges2608 bronze badges
815k206 gold badges2213 silver badges2608 bronze badges
answered Mar 27 at 7:22
Gareth BalfourGareth Balfour
1461 silver badge6 bronze badges
1461 silver badge6 bronze badges
add a comment |
add a comment |
you can use ExecuteScalarAsync() instead of ExecuteAsync().Because it return a single value. when you will use select statement in SP
hope this works
add a comment |
you can use ExecuteScalarAsync() instead of ExecuteAsync().Because it return a single value. when you will use select statement in SP
hope this works
add a comment |
you can use ExecuteScalarAsync() instead of ExecuteAsync().Because it return a single value. when you will use select statement in SP
hope this works
you can use ExecuteScalarAsync() instead of ExecuteAsync().Because it return a single value. when you will use select statement in SP
hope this works
edited Mar 27 at 7:04
answered Mar 27 at 6:59
Deepankshee JainDeepankshee Jain
814 bronze badges
814 bronze badges
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55371357%2fusing-dapper-by-stored-procedure%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Try changing
ExecuteAsync(..)
toExecuteScalarAsync<bool>(...)
– Simply Ged
Mar 27 at 6:58
How do you return the result from the stored procedure, with a
return
statement or by using aselect
?– Dirk
Mar 27 at 7:02
Drik, I am using select statement in stored procedure
– Ali
Mar 27 at 7:12
@Ali in this case the
ExecuteScalarAsync
method proposed in the answers will work. For return values this works a bit different (using a parameter withParameterDirection.ReturnValue
)– Dirk
Mar 27 at 7:41
The point ultimately here is that the result of
ExecuteAsync
is the same as the result ofDbCommand.ExecuteNonQueryAsync
- and the integer result of that is not anything to do with anything youselect
orreturn
- it is a separate thing. If you want toselect
a result, you're closer toDbCommand.ExecuteScalarAsync
, which dapper makes available via an extension method of the same name– Marc Gravell♦
Mar 27 at 8:25