是否可以使用dataBase.executeNonQuery并使用存储过程中的返回值?

Is it possible to use dataBase.executeNonQuery and use a return value from a stored proc?
2020-10-18
  •  译文(汉语)
  •  原文(英语)

我做了一些研究,发现了一些关于如何使用存储过程中的返回值的想法:

using (SqlCommand cmd = conn.CreateCommand())
{
    cmd.CommandText = parameterStatement.getQuery();
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.Parameters.AddWithValue("SeqName", "SeqNameValue");

    var returnParameter = cmd.Parameters.Add("@ReturnVal", SqlDbType.Int);
    returnParameter.Direction = ParameterDirection.ReturnValue;

    conn.Open();
    cmd.ExecuteNonQuery();
    var result = returnParameter.Value;
}

但是我正在使用这样的东西:

Database.AddInParameter();

在这里我不必打开和关闭连接.

某些机构可以帮助我了解是否可以通过数据库方法使用Direction.Returnvalue吗?

抱歉,您的问题有点混乱:)请随时询问是否不清楚

速聊1:
cmd.ExecuteScalar()呢 我不确定您要什么.您是专门使用Return-Parameter还是只想从proc中访问返回值?
速聊2:
我只想从我的proc .. lemme中获取返回值,请检查cmd.ExecuteScalar是否适合我的要求.
速聊3:
Eckebrecht 1感谢您的评论.实际上,我想将EnterpriseLibrary.Data.Database对象与执行非查询方法而不是command一起使用.execute <something>由于代码是预先编写的,我不想对其进行太多更改
速聊4:
喔好吧.不太清楚.也许改一下,让其他人更好地理解.
速聊5:
我有点着急,所以无法以更好的方式格式化和表达我的问题:),但是我得到了一个对我来说效果很好的解决方案,我使用了DataBase.outParameter ..
解决过程1

使用database.outParameter作为返回值的参数

I have done some research and found a few ideas on how we can use a return value from a stored proc like:

using (SqlCommand cmd = conn.CreateCommand())
{
    cmd.CommandText = parameterStatement.getQuery();
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.Parameters.AddWithValue("SeqName", "SeqNameValue");

    var returnParameter = cmd.Parameters.Add("@ReturnVal", SqlDbType.Int);
    returnParameter.Direction = ParameterDirection.ReturnValue;

    conn.Open();
    cmd.ExecuteNonQuery();
    var result = returnParameter.Value;
}

but i am using something like this:

Database.AddInParameter();

where i do not have to open and close connections..

Can some body help me to understand if it is possible to use Direction.Returnvalue using DataBase approach?

Sorry for a bit un-organized question :) please feel free to ask if anything is not clear

Talk1:
What about cmd.ExecuteScalar() ? I'm not sure what you're asking for. Do you specifically want to use a Return-Parameter or du you just want to access the return value from your proc?
Talk2:
i just want to access return value from my proc.. lemme check out cmd.ExecuteScalar if it suits my requirement.. Thanks in Advance!
Talk3:
Eckebrecht 1 thanks for ur comment. Actually i wanted to use EnterpriseLibrary.Data.Database object with execute non query method instead of command . execute<something> As the code is pre-written and i dont want to change it much
Talk4:
Ah ok. Not very clear. Maybe rephrase a bit for others to understand better.
Talk5:
i was in a bit hurry so could not format and phrase my question in a better way :) but i got a solution that worked perfectly fine for me i used DataBase.outParameter ..
Solutions1

use database.outParameter for parameters that return value

转载于:https://stackoverflow.com/questions/30774336/is-it-possible-to-use-database-executenonquery-and-use-a-return-value-from-a-sto

本人是.net程序员,因为英语不行,使用工具翻译,希望对有需要的人有所帮助
如果本文质量不好,还请谅解,毕竟这些操作还是比较费时的,英语较好的可以看原文

留言回复
我们只提供高质量资源,素材,源码,坚持 下了就能用 原则,让客户花了钱觉得值
上班时间 : 周一至周五9:00-17:30 期待您的加入