需要从SQL检索一些数据以及使用out参数插入 [英] Need to retrieve some data from SQL as well as insert with out using out parameter

查看:62
本文介绍了需要从SQL检索一些数据以及使用out参数插入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有一个存储过程,它会将一些数据插入到表中,然后在sql中检索一些数据。在使用c#的前端,我需要从我的程序中取回结果集并需要使用它。



我需要使用哪种语句?我发现executereader()是解决方案,但这不起作用。我不应该按照公司编码标准在sql和c#中使用out参数。有人可以用一个例子来解释这个吗?



存储过程

Hi,

I have a stored procedure which will insert some data into a table, and retrieve back some data in sql. In front end using c#, i need to fetch back the result set from my procedure and need to use it.

Which statement i need to use? I found that executereader() is the solution, but this is not working. I should not use the out parameter in sql as well as c# as per company coding standards. Can anybody explain this with an example?

stored procedure

create procedure name
@patientId
as
begin
insert into table values(a,b,c);
select * from table where value = a;
end


$ C $ b in C#


in C#

var reader = cp.executereader();
var a=reader["value"].tostring();



这是我实现我的功能的方式(仅限于表示)。



我尝试过:




This is the way i have implemented my functionality(representational only).

What I have tried:

create procedure name
@patientId
as
begin
insert into table values(a,b,c);
select * from table where value = a;
end


$ C $ b in C#


in C#

var reader = cp.executereader();
var a=reader["value"].tostring();



这是我实现我的功能的方式(仅代表性)。


This is the way i have implemented my functionality(representational only).

推荐答案

假设您已建立了与数据库的有效连接并已成功创建表中的记录。



插入记录后,您可以选择该记录,它将在数据阅读器中返回。

Presuming you have made a valid connection to the database and have successfully created the record in the table.

After you have inserted the record you can select that record and it will be returned in the data reader.
Insert TableName
(Field1,Field2)
Value (@Value1, Value2)

SET @ID = Scope_Identity() -- gets the last ID from and identity field

Select * From TableName where ID = @ID



这是你从任何关于CRUD的文章中得到的基本内容 - 做一些研究。



顺便说一句,你上面写的存储过程绝对没有意义,也没有你描述的任何内容。


This is really basic stuff you can get from any article on CRUD - do some research.

BTW you stored procedure as written above makes absolutely no sense and does nothing you described.


这篇关于需要从SQL检索一些数据以及使用out参数插入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆