我需要从asp页面调用我在SQL 2008中的存储过程并向其传递两个值,最后返回两个变量的计数。
这是我的存储过程:
/****** STUDATATAB******/
CREATE PROCEDURE StdntReconcileDups @NewSTDNT int = NULL, @OldSTDNT int = NULL output
AS
--use ZLDP01RD;
--count = 9 rows
Select count (*) from STUDATA.dbo.STUDATATAB
where STDNT = @NewSTDNT;
-- count = 576 rows
select count(*) from STUDATA.dbo.STUDATATAB
where STDNT = @OldSTDNT;
-- select duplicate keys with new student# count = 3 rows
select a.STDNT,a.crs,a.CRS_VRSN,a.QSTN,a.SCR
from STUDATA.dbo.STUDATATABa, STUDATA.dbo.STUDATATABb
where a.STDNT = @NewSTDNT
and b.STDNT = @OldSTDNT
and a.crs = b.crs
and a.CRS_VRSN=b.CRS_VRSN
and a.QSTN=b.QSTN
and a.SCR=b.SCR
-- select duplicate keys with new student# count = 3 rows
select count (*)
from STUDATA.dbo.STUDATATABa
where exists (select 1 from STUDATA.dbo.STUDATATABb
where a.STDNT = @NewSTDNT
and b.STDNT = @OldSTDNT
and a.crs = b.crs
and a.CRS_VRSN=b.CRS_VRSN
and a.QSTN=b.QSTN
and a.SCR=b.SCR );
-- delete duplicate keys with new student# 3 rows deleted
WITH STUDENT_CTE
AS
(select a.*
from STUDATA.dbo.STUDATATABa
where exists (select 1 from STUDATA.dbo.STUDATATABb
where a.STDNT = @NewSTDNT
and b.STDNT = @OldSTDNT
and a.crs = b.crs
and a.CRS_VRSN=b.CRS_VRSN
and a.QSTN=b.QSTN
and a.SCR=b.SCR ))
delete from STUDENT_CTE;
--Convert student #10826 history records to student #123196, should update 579 rows
UPDATE STUDATA.dbo.STUDATATAB
SET STDNT = @NewSTDNT, LSTUPDT_USER_ID_CD = 'DFERN', LSTUPDT_TS = getDate()
where STDNT = @OldSTDNT;
-- count= 582
select count(*) from STUDATA.dbo.STUDATATAB
where STDNT = @NewSTDNT;
-- count= 0
Select count(*) from STUDATA.dbo.STUDATATAB
where STDNT = @OldSTDNT;
go
我想在if参数中插入代码,因此它调用StdntReconcileDups并将KeepSTDNT和RemoveSTDNT的值传递给它
Dim DBConn ' Connection object
If Request.Form("Action") = "Go!" then
Endif
答案 0 :(得分:0)
这个概念是执行你的请求...你会得到一个记录集,你将迭代直到你得到eof ...然后你将调用下一个记录集来获得下一个结果。
......你在找这样的东西吗?
connectstring = "..."
sql = "StdntReconcileDups '" & NewSTDNT & "','" & OldSTDNT & "'"
set rs = Server.CreateObject("ADODB.RecordSet")
rs.Open sql, connectstring, 3
答案 1 :(得分:0)
如果我理解了你的意思......那就像下面这样:
SqlConnection con = new SqlConnection("Data Source= ; initial catalog= Northwind ; User Id= ; Password= '");
con.open();
创建SqlConnection后,您将创建如下所示的Storedprocedure:
CREATE PROCEDURE RegionUpdate (@RegionID INTEGER,@RegionDescription NCHAR(50)) AS
SET NOCOUNT OFF
UPDATE Region
SET RegionDescription = @RegionDescription
使用参数作为要执行的存储过程的名称以及将命令发送到其中以执行的连接对象con来创建SqlCommand对象。
SqlCommand command = new SqlCommand("RegionUpdate",con);
将命令对象CommandType属性更改为存储过程。
command.CommandType = CommandType.StoredProcedure;
使用Parameters集合和SqlParameter类将参数添加到命令对象。
command.Parameters.Add(new SqlParameter("@RegionID",SqlDbType.Int,0,"RegionID"));
command.Parameters.Add(new SqlParameter("@RegionDescription",SqlDbType.NChar,50,"RegionDescription"));
使用参数的Value属性
指定参数的值 command.Parameters[0].Value=4;
command.Parameters[1].Value="SouthEast";
使用ExecuteNonQuery方法超出存储过程,该方法返回存储过程影响的行数。
int i=command.ExecuteNonQuery();
上面的代码是正确的方法......您可以完全替换 @KeepSTDNT 和 @RemoveSTDNT 而不是 @RegionID 和 @RegionDescription ...我自己也用过它...如果你想要更多的帮助......那就说吧