VB3 How to Call SQL Stored Procedures from Visual BasicLast reviewed: January 29, 1997Article ID: Q106492 |
The information in this article applies to:
- Professional Edition of Microsoft Visual Basic for Windows, version 3.0
SUMMARYThis article describes how to call Microsoft SQL stored procedures from Visual Basic. A stored procedure is a precompiled collection of SQL statements, often including control-of-flow language.
MORE INFORMATIONThe method of calling depends on whether the SQL stored procedure returns records or not:
How to Pass Parameters to a Stored ProcedureTo pass parameters, include them after the name of the stored procedure in a string, for example:
SQLx = "My_StorProc parm1, parm2, parm3" ' String specifying SQL ' command. ... i = MyDB.ExecuteSQL(SQLx) ' For stored procedure that ' doesn't return records. ... set Ds = MyDB.CreateDynaset(SQLx,64) ' For stored procedure that ' returns records.The object variable (Ds) will contain the first set of results from the stored procedure (My_StorProc).
Another ExampleHere's more example code showing both methods:
Dim db as Database; l as long; Ss as Snapshot ' Enter the following two lines as one, single line: Set Db = OpenDatabase ("",false,false, "ODBC;dsn=yourdsn;uid=youruid;pwd=yourpwd") l=ExecuteSQL("YourSP_Name") ' for SPs that don't return rows Set Ss = Db.CreateSnapshot("YourSP_Name", 64) ' for SPs that return rows Col1.text = Ss(0) ' Column one Col2.text = Ss!ColumnName Col3.Text=Ss("ColumnName") REFERENCESMore information about calling stored procedures is documented in the following Microsoft SQL manual which covers the Visual Basic Library for SQL Server:
|
KBCategory: kbprg
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |