- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
您好,我想获取输出参数的值以及选择查询的结果集。
我使用了 ExecuteNonQuery
,它为输出参数提供了正确的值。
我使用 ExecuteReader
它没有为输出参数提供正确的值,但它为选择查询提供了正确的值。
那么我应该使用什么来获得这两个结果。
ALTER PROCEDURE [dbo].[XYZ]
(
@szUserName varchar(50),
@iOutDistinceBankCount int out
)
AS
BEGIN
declare @iCountDistinctBanks int;
set @iCountDistinctBanks = (select count (distinct a.DCC_BANK_ID )
from DEF a with(nolock)
join ABC b with(nolock) on
a.ROLEID = b.ROLEID
where b.USERNAME = @szUserName and b.STATUS_ID = 2)
if ((@iCountDistinctBanks > 1) or (@iCountDistinctBanks = 0))
begin
set @iOutDistinceBankCount = @iCountDistinctBanks
end
else
begin
set @iOutDistinceBankCount = 1;
select a.DCC_BANK_ID as DCC_BANK_ID
from DEF a with(nolock)
join ABC b with(nolock) on
a.ROLEID = b.ROLEID
where b.USERNAME = @szUserName and b.STATUS_ID = 2
end
END
这是我的 C# 代码。
Int32 i32DistinctDCCBankCount = -1;
Int64 i64BankStaticID = -1;
InitDB();
m_command = new SqlCommand("DCC_spUIDCCBankIdAccordingUser", m_con);
m_command.Parameters.Add("@szUserName", System.Data.SqlDbType.VarChar, 50).Value = MerchantName;
SqlParameter output = new SqlParameter("@iOutDistinceBankCount", System.Data.SqlDbType.Int);
output.Direction = System.Data.ParameterDirection.Output;
m_command.Parameters.Add(output);
m_command.CommandType = System.Data.CommandType.StoredProcedure;
m_con.Open();
// m_reader = m_command.ExecuteReader();
m_command.ExecuteNonQuery();
i32DistinctDCCBankCount = Convert.ToInt32(m_command.Parameters["@iOutDistinceBankCount"].Value);
if (i32DistinctDCCBankCount == 0)
{
iDistinctDCCBankCount = 0;
return i32DistinctDCCBankCount;
}
else if (i32DistinctDCCBankCount > 1)
{
iDistinctDCCBankCount = i32DistinctDCCBankCount;
return -2;
}
else if (i32DistinctDCCBankCount == 1)
{
i64BankStaticID = Convert.ToInt64(m_reader["DCC_BANK_ID"]);
iDistinctDCCBankCount = i32DistinctDCCBankCount;
return i64BankStaticID;
}
iDistinctDCCBankCount = 0;
return 0;
最佳答案
可以使用 Command.ExecuteReader(或者 ExecuteNonQuery ,如果您没有要处理的行集)直接执行相同的查询, 但是您还需要采取其他几个步骤来处理返回值。请记住,您必须在 try catch 返回值或 OUTPUT 参数之前完成对所有行集的处理。以下代码显示如何使用 ExecuteReader 和循环来处理行集,然后捕获返回值和 OUTPUT 参数。您会发现 OUTPUT 参数(甚至很多参数)的处理速度甚至比 SELECT 返回的单行数据快得多。
这里是例子
With cmd.Parameters
cn.Open()
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
' Process rowset(s)
bolEOF = dr.Read
Do
Do While bolEOF = True
' Process rows
bolEOF = dr.Read()
Loop
Loop While dr.NextResult = True
cmd.Cancel()
// you need to close dataReader first
dr.Close()
Debug.WriteLine("@iOutDistinceBankCount:" & _
.Item("@iOutDistinceBankCount").Value.ToString)
End With
关于c# - 如何在ado.net中使用输出参数和选择sql server存储过程的查询结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22728814/
我刚刚读过“Injecting Custom Logic in ADO.NET Data Services”,我的下一个问题是,如何使[WebGet]方法显示在客户端代理类中?当然,我可以直接使用We
我需要学习 ADO.NET 来构建基于 MS Office 的应用程序。我在 MSDN 库中阅读了大量有关 ADO.NET 的内容,但对我来说,一切都显得相当困惑。 使用 ADO.NET 时必须了解哪
所以这是交易。在我们的数据库中,出于安全性和模块化的目的,我们将大部分读取(即选择语句)包装在表值函数中。所以我有一个定义一个或多个可选参数的 TVF。 我相信具有默认参数的 TVF 要求使用关键字
我需要通过 ADO.NET 创建一个临时表,执行一个 BulkCopy然后是 Merge在临时表和实际表之间的服务器上。 问题是使用纯 ADO.NET 创建动态临时表。 架构应该与现有表相同,但该表是
我开发了一个带有自定义数据库配置的产品。我将 ADO.NET 与 System.Data.Odbc.OdbcConnection 结合使用。为了在数据库之间做出一些区别,有一个简单的解决方案来检测连接
我有一些 friend 是“老派”VB6 数据库开发人员,我向他们介绍了 .NET 及其功能,特别是 ADO.NET。 在我们的谈话中,他们提出了为什么他们宁愿坚持使用 ADO 而不是转向 ADO.N
我有一个有 6 列的数据库表。主键是由 6 列中的 5 列组成的复合键 我正在尝试使用 SqlClient.SqlCommandBuilder.GetDeleteCommand删除该行。 但是我收到以
我已经编写了一个围绕 ADO.NET 的 DbProviderFactory 的包装器,我在我的应用程序中广泛使用它。我还编写了很多将 IDataReader 行映射到 POCO 的代码。然而,由于我
我知道这已经被问过了。 大多数答案都不相关。 谷歌,显示解决方案是在“数据流任务”中配置表达式并设置查询。 然而,在 ADO .NET 源代码中,当我尝试预览输出时,我不断收到 "Must decla
我的代码如下: var statement = "test_oracle.sql"; F = aqFile.OpenTextFile(statement, aqFile.faRead, aqF
可以从 MATLAB 调用 .NET,所以我想我会尝试使用 ADO.NET 连接到数据库。 我似乎遇到了一个阻塞问题 - 无论何时您尝试创建一个 Command 对象,它都会抛出一个错误。 你可以自己
在中发现的物体之间有什么类比? JDBC 以及在 中找到的那些ADO.Net ? 我知道 JDBC 和 ADO.Net 中的对象模型并不完全相同,但我认为可以在它们之间找到一些类比(以及值得说明的关键
我有一个在 DbProviderFactory 的 machine.config 中注册的 ADO.NET 托管数据提供程序 - 它可供 Analysis Services 使用,因此我知道它已正确注
我一直在阅读有关 TransactionScope 的内容,并对它与 ADO.Net 事务的互操作性有疑问。现在我们有一些数据访问方法,每个方法都调用存储过程并开始和提交自己的单独事务。简单明了,样板
是否可以在不借助 DataAdapter 的情况下在 ADO.NET 中实现多个存储过程调用的批处理(执行更新/删除)? 最佳答案 您可以尝试使用 System.Data.SqlClient.SqlC
是否可以获取 OleDbCommand 的文本?用它们的值替换所有参数?例如。在下面的代码中,我正在寻找一种获取查询文本的方法 SELECT * FROM my_table WHERE c1 = 'h
什么更快 - ADO.NET 或 ADO.NET Entity Framework ? 最佳答案 没有什么比 ADO.NET 数据读取器更快了。 Entity Framework 也在“地下室”中使用
我需要 .NET Core 上的 ODP.NET(适用于 .NET 的 Oracle 数据提供程序),但无论如何找不到使其工作。 当我引用 OracleConnection 或 OracleComma
我正在启动一个基于 ASP.NET 和 Windows 服务器的新项目。 该应用程序计划非常大,并且为大量客户端提供高频拉取和更新服务。更改数据。 我之前曾使用 Linq-To-Sql 或 Ado.N
有没有其他快速的方法来在 ADO.Net 中填充数据表而不使用 Data adaptor.Fill 方法? 最佳答案 是的,你可以。这是一个简短的例子: var results = new DataT
我是一名优秀的程序员,十分优秀!