• Status: Solved
  • Priority: High
  • Security: Public
  • Views: 111
  • Last Modified:

Launch stored procedure (SQL Server) from classic asp/VB page...

Hi there.

I have  this stored procedure as you can see here:

Save-query-generated-from-stored-procedure-to-table

It has got a build in parameter Y/N whether it shall create/flush a table or not. How do I run the SP via VB code? And can I kinda build in the Y or N when launching it via VB?

Best regards

Ulrich
0
ullenulle
Asked:
ullenulle
2 Solutions
 
Ryan ChongCommented:
here is an example:

Calling a Stored Procedure using ADO in a VBScript
https://thehouseofvb.wordpress.com/2010/10/11/calling-a-stored-procedure-using-ado-in-a-vbscript/

try remove the server. when you declare your object.

Set cn = Server.CreateObject("ADODB.Connection")
   Set cmd = Server.CreateObject("ADODB.Command")
0
 
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
I looked on your previous question and that only links to another question.  It is too confusing to help like this. The best thing is to add your actual code in the question here. Just post in the next comment.  

Otherwise, a quick example

Set cmd = Server.CreateObject("ADODB.Command")
With cmd
   ' Set up DB connection to use, set the type of SQL command
   	.ActiveConnection = connection_string
   	.CommandType = adCmdStoredProc
   	.CommandText = "stored_proc_name" '
   
   	.Parameters.Append .CreateParameter("@1",adVarWChar, adParamInput, 30)
   	.Parameters("@1") = variable
   

   set rs = .Execute
End With

  result= rs(0)

set cmd = nothing
set rs = nothing

Open in new window



The key is your establishing an output as a recordset and now you can access the return data just like any recordset you create.
0
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
Scott has given you a good clear example. I just wanted to add one more thing. On the line:

.Parameters.Append .CreateParameter("@1",adVarWChar, adParamInput, 30)

you'll see two constants being used, adVarWChar and adParamInput. You will need to download and include the standard adovbs.inc file in order to define those constants.
1
 
Eugene ZCommented:
try this MSFT educational article with examples

How to call SQL Server stored procedures in ASP.NET by using Visual Basic .NET

https://support.microsoft.com/en-us/help/306574/how-to-call-sql-server-stored-procedures-in-asp-net-by-using-visual-ba



or use EE another samples solutions ( unless you have already checked them)

like this one
https://www.experts-exchange.com/questions/24992653/calling-SQL-stored-proc-from-classic-ASP.html

or this

https://www.experts-exchange.com/questions/28459662/Return-Value-of-Stored-Procedure-in-Classic-ASP.html
0
 
ullenulleAuthor Commented:
Hi guys.

Thank you for your input. I will check it out the next few days. I've been travelling.

Best regards

Ulrich
1
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now