c# - 如何从 ASPx 页面向 sqlserver 发送一个 ref int 值?

标签 c# sql sql-server data-access-layer

我有这个返回 UserID 的存储过程:

ALTER PROCEDURE dbo.GetUserID
(
@TopicID int, 
    @AskerID int
)
AS
SELECT       @AskerID = Post.Pt_CreatedBy 
WHERE        (Topic.Tp_ID = @TopicID)
RETURN @AskerID

现在当我使用 C# 从数据访问层页面调用它时,我使用这个函数:

 MyDatabaseDataContext StudyAppdb = new MyDatabaseDataContext();

public int GetUserID(int TopicID)
    {
        int UserID = -1;
        UserID = db.GetUserID(TopicID, UserID);
        return UserID;
    }

但是 GetUserID 应该采用 (int , ref int)...。我不知道什么是 ref int 以及如何将它传递给函数。

最佳答案

由于 GetUserID 应该采用 (int , ref int),因此在调用此方法时还应明确使用 ref 关键字。不要使用 db.GetUserID(TopicID, UserID) 调用方法,您应该使用 ref 关键字,例如:

public int GetUserID(int TopicID)
{
    int UserID = -1;
    UserID = db.GetUserID(TopicID, ref UserID);
    return UserID;
}

您可以阅读更多关于 ref keyword 的信息.

关于c# - 如何从 ASPx 页面向 sqlserver 发送一个 ref int 值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12245193/

相关文章:

c# - 固定 .NET 对象数组

c# - 当类型参数为 IEnumerable<T> 时,如何将扩展方法附加到泛型类?

mysql - SQLite 中拉丁语和英语名称的条件排序

sql - 如何使用相同的约束映射不同的多对多

python - 远程连接到 MS SQL - 使用 pyodbc 时出错与使用 SQL Server Management Studio 时成功

c# - SQL Server 不将十进制值传递给 C#

c# - maskedTextBox C# 中的 IP 地址验证

python - PostgreSQL 获取从主键到外键的序列值

sql - 为什么我得到 "A cursor with the name already exists"?

c# - 无法将 MySQL 日期/时间值转换为 System.DateTime