简体   繁体   English

如何从存储过程中获取结果作为值?

[英]How to get a result from a stored procedure as value?

I had a similar question last week where I got good help so I'm trying again. 上周我也遇到了类似的问题,在这里我得到了很好的帮助,所以我再次尝试。

Basically I have this stored procedure where I input a string and get out an int from a table in the database. 基本上,我有这个存储过程,在这里我输入一个字符串并从数据库的一个表中获取一个int值。 I would like to use this int for another stored procedure. 我想将此int用于另一个存储过程。

The problem is I don't know how to just get the actual value from my stored procedure result. 问题是我不知道如何仅从存储过程结果中获取实际值。 If I wanted to I could show the output in a datagrid or something, but I don't want that. 如果我愿意,可以将输出显示在datagrid之类的东西中,但我不想要那样。 I just want the value in my program to be used for something else. 我只想将程序中的值用于其他用途。 How do I do this? 我该怎么做呢?

Here is the SP: 这是SP:

@EquipmentTypeDesignation NVARCHAR(50)

AS

SELECT EquipmentType.EquipmentTypeID
FROM EquipmentType
WHERE EquipmentTypeDesignation = @EquipmentTypeDesignation

I would like to just do something like this: 我只想做这样的事情:

DataClasses1DataContext context = new DataClasses1DataContext();

...

var s = context.ReadEquipmentTypeDesignationSP("S9");
s.EquipmentTypeID somethingsomething something

I feel like I'm missing something basic here so thank you for your help. 我觉得我在这里缺少一些基本知识,因此谢谢您的帮助。

@EquipmentTypeDesignation NVARCHAR(50)

AS

DECLARE @equipTypeId int

SELECT top 1 @equipTypeId = EquipmentType.EquipmentTypeID
FROM EquipmentType
WHERE EquipmentTypeDesignation = @EquipmentTypeDesignation

RETURN @equipTypeId

in your code 在你的代码中

var equipTypeId = context.ReadEquipmentTypeDesignationSP("S9").FirstOrDefault();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM