| VB3 How to Call SQL Stored Procedures from Visual BasicID: Q106492 
 | 
This 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.
The method of calling depends on whether the SQL stored procedure returns
records or not:
      i% = MyDb.ExecuteSQL("sp_name")
 
      Delete Authors where name like "fred%"
 
      DB_SQLPassThrough = 64
      Data1.Options = DB_SQLPassThrough
      Data1.Recordsource = "sp_name"  ' name of the stored procedure
      Data1.Refresh   ' Refresh the data control
 
      Dim Ds as Dynaset
      Set MyDB = OpenDatabase(... ' Open your desired database here.
      Set Ds = MyDB.CreateDynaset("sp_name",Db_SQLPassThrough)
      ' You can also Dim as Snapshot and use MyDb.CreateSnapshot above.
 
   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. 
   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") 
More information about calling stored procedures is documented in the
following Microsoft SQL manual which covers the Visual Basic Library
for SQL Server:
Additional query words: 3.00
Keywords          : 
Version           : 3.00
Platform          : WINDOWS 
Issue type        : Last Reviewed: June 16, 1999