Imports SystemImports System.DataImports System.Data.OleDbModule CreateSPSub Main()ProductsProcs()End Sub' Products Stored Procs to be added to the db.Sub ProductsProcs()Dim sSQL As String' procProductsList - Retrieves entire tablesSQL = "CREATE PROC procProductsList AS SELECT * FROM Products;"CreateStoredProc(sSQL)' procProductsDeleteItem - Returns the details (one record) from the ' JobTitle tablesSQL = "CREATE PROC procProductsDeleteItem(@ProductID LONG) AS " _& "DELETE FROM Products WHERE ProductID = @ProductID;"CreateStoredProc(sSQL)' procProductsAddItem - Add one record to the JobTitle tablesSQL = "CREATE PROC procProductsAddItem(inProductName VARCHAR(40), " _& "inSupplierID LONG, inCategoryID LONG) AS INSERT INTO " _& "Products (ProductName, SupplierID, CategoryID) Values " _& "(inProductName, inSupplierID, CategoryID);"CreateStoredProc(sSQL)' procProductsUpdateItem - Update one record on the JobTitle tablesSQL = "CREATE PROC procProductsUpdateItem(inProductID LONG, " _& "inProductName VARCHAR(40)) AS UPDATE Products SET " _& "ProductName = inProductName WHERE ProductID = inProductID;"CreateStoredProc(sSQL)End Sub' Execute the creation of Stored ProceduresSub CreateStoredProc(ByVal sSQL As String)Dim con As OleDbConnectionDim cmd As OleDbCommand = New OleDbCommand()Dim da As OleDbDataAdapter' Change Data Source to the location of Northwind.mdb on your local ' system.Dim sConStr As String = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data " _& "Source=C:\Program Files\Microsoft " _& "Office\Office10\Samples\Northwind.mdb"con = New OleDbConnection(sConStr)cmd.Connection = concmd.CommandText = sSQLcon.Open()cmd.ExecuteNonQuery()con.Close()End SubEnd Module
(未完待续)
……