求助:asp+Sql Server 存储过程
此段是SqlServer存储过程:CREATEprocedure[dbo].[News_ADD](@News_Titlevarchar(50),@News_IDvarch...
此段是Sql Server 存储过程:
CREATE procedure [dbo].[News_ADD]
(@News_Title varchar(50),
@News_ID varchar(21) output)
as
set nocount on
begin
if not exists(select News_Title from table1 where News_Title = @News_Title)
begin
declare @RND varchar(6)
while exists(select News_ID from table1 where News_ID = @News_ID) or @News_ID = '' or @News_ID is null
begin
set @News_ID = replace(replace(replace(CONVERT(varchar, getdate(), 120 ),'-',''),' ',''),':','')
while @RND is null or @RND = '' or len(@RND) < 6
begin
set @RND = cast(cast(rand() * 1000000 as int) as varchar(6))
end
set @News_ID = @News_ID + '-' + @RND
end
insert into table1 values(@News_ID,@News_Title)
return 1
end
else
begin
return 0
end
end
该存储过程在SQL Server Management Studio 中测试正常,可以获得返回值 "return" 和 "@News_ID"
以下是ASP调用代码:
dim cmd,News_Title
News_Title = request.Form("News_Title")
set cmd = server.CreateObject("ADODB.Command")
with cmd
.ActiveConnection = conn
.commandtext = "News_sel"
.commandtype = 4
.prepared = true
.parameters.append .createparameter("@News_ID",200,2,21)
.parameters.append .createparameter("@News_Title",200,1,50,News_Title)
.execute
end with
response.Write(cmd.parameter(0))
set cmd = nothing
该段asp代码无法获取返回值 "return" 和 "@News_ID" 展开
CREATE procedure [dbo].[News_ADD]
(@News_Title varchar(50),
@News_ID varchar(21) output)
as
set nocount on
begin
if not exists(select News_Title from table1 where News_Title = @News_Title)
begin
declare @RND varchar(6)
while exists(select News_ID from table1 where News_ID = @News_ID) or @News_ID = '' or @News_ID is null
begin
set @News_ID = replace(replace(replace(CONVERT(varchar, getdate(), 120 ),'-',''),' ',''),':','')
while @RND is null or @RND = '' or len(@RND) < 6
begin
set @RND = cast(cast(rand() * 1000000 as int) as varchar(6))
end
set @News_ID = @News_ID + '-' + @RND
end
insert into table1 values(@News_ID,@News_Title)
return 1
end
else
begin
return 0
end
end
该存储过程在SQL Server Management Studio 中测试正常,可以获得返回值 "return" 和 "@News_ID"
以下是ASP调用代码:
dim cmd,News_Title
News_Title = request.Form("News_Title")
set cmd = server.CreateObject("ADODB.Command")
with cmd
.ActiveConnection = conn
.commandtext = "News_sel"
.commandtype = 4
.prepared = true
.parameters.append .createparameter("@News_ID",200,2,21)
.parameters.append .createparameter("@News_Title",200,1,50,News_Title)
.execute
end with
response.Write(cmd.parameter(0))
set cmd = nothing
该段asp代码无法获取返回值 "return" 和 "@News_ID" 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询