通过调用存储过程不但能返回值,还能返回一张表,下面的代码中实现了创建一个临时表,并返回这个表(支持多个)的用法。希望对大家有帮助,
Examda提示: 这里还涉及到一个临时表的创建,什么是sql server真正的临时表,并发不冲突的临时表,要让系统建立在tempdb中才是,sql server会自动管理这些临时表
c#代码如下
DataSet ds = new DataSet();
System.Data.OleDb.OleDbCommand cmd = m_TdlyDataAccess.DBConnection.CreateCommand();
cmd.CommandText = "prcTest";
cmd.CommandType = CommandType.StoredProcedure;
System.Data.OleDb.OleDbDataAdapter dap = new System.Data.OleDb.OleDbDataAdapter(cmd);
dap.Fill(ds);
存储过程如下
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[prcTest]
AS
begin
CREATE TABLE #t(x INT PRIMARY KEY,y int default 0,z int default 0)
INSERT INTO #t VALUES (99,0,0)
INSERT INTO #t VALUES (239,0,0)
INSERT INTO #t VALUES (939,0,0)
select * from #t
drop table #t
end
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
阅读(1194) | 评论(0) | 转发(1) |