bertrandkis
Programmer
I need to execute an asp script that calls a stored procedure on SQL server.Each time a form button is clicked the result of the query executed by the asp script must be shown on a form field.With the script I have writen the textbox value stays the same event if the stored procedure returns different values each time it is executed. Here is the code.
<html>
<body>
<script >
function rep()
{
<% SET cn=server.CreateObject("adodb.connection"
with cn
.ConnectionString ="Provider=sqloledb;datasource=(local);uid=sa"
.Open
.DefaultDatabase ="Test database"
end with
%>
<%
dt="3/11/2002"
set rs=server.CreateObject("adodb.recordset"
set rs=cn.Execute("testproc '"& dt &"'" ,,adCmdStoredProc)
response.write("foo=" & rs.fields(0))
%>
document.f1.t1.value= foo;
}
</script>
<form name=f1>
<input type=text name=t1 >
<input type=button name=b2 value="New nber" onclick="rep()">
</form>
</body>
</html>
The text of the stored procedure is:
create proc testproc @d datetime
as
begin
set dateformat dmy
declare @n int,@k int
set @k=0
set @n=rand()*20+1
while @k=0
begin
if exists(select * from testnumbers where testcode=@n and testdate=@d)
begin
set @n=rand()*20+1
continue
end --end if
else
break
end --end while
select @n --create a recordset
end -- end of proc
The content of the table against which the stored procedure executes:
----------------------------------------
testcode Testdate
----------- ----------------------
7 2002-03-11 00:00:00.000
8 2002-03-11 00:00:00.000
9 2002-03-11 00:00:00.000
10 2002-03-11 00:00:00.000
6 2002-03-11 00:00:00.000
I will appreciate your help and if you can email me directly at bertrandkis@usa.com I will appreciate, the project I am working on has come to a dead end because of this problem. Thank you
<html>
<body>
<script >
function rep()
{
<% SET cn=server.CreateObject("adodb.connection"
with cn
.ConnectionString ="Provider=sqloledb;datasource=(local);uid=sa"
.Open
.DefaultDatabase ="Test database"
end with
%>
<%
dt="3/11/2002"
set rs=server.CreateObject("adodb.recordset"
set rs=cn.Execute("testproc '"& dt &"'" ,,adCmdStoredProc)
response.write("foo=" & rs.fields(0))
%>
document.f1.t1.value= foo;
}
</script>
<form name=f1>
<input type=text name=t1 >
<input type=button name=b2 value="New nber" onclick="rep()">
</form>
</body>
</html>
The text of the stored procedure is:
create proc testproc @d datetime
as
begin
set dateformat dmy
declare @n int,@k int
set @k=0
set @n=rand()*20+1
while @k=0
begin
if exists(select * from testnumbers where testcode=@n and testdate=@d)
begin
set @n=rand()*20+1
continue
end --end if
else
break
end --end while
select @n --create a recordset
end -- end of proc
The content of the table against which the stored procedure executes:
----------------------------------------
testcode Testdate
----------- ----------------------
7 2002-03-11 00:00:00.000
8 2002-03-11 00:00:00.000
9 2002-03-11 00:00:00.000
10 2002-03-11 00:00:00.000
6 2002-03-11 00:00:00.000
I will appreciate your help and if you can email me directly at bertrandkis@usa.com I will appreciate, the project I am working on has come to a dead end because of this problem. Thank you