imports systemimports system.dataimports system.data.oledbmodule createsp sub main() productsprocs() end sub ' products stored procs to be added to the db. sub productsprocs() dim ssql as string ' procproductslist - retrieves entire table ssql = "create proc procproductslist as select * from products;" createstoredproc(ssql) ' procproductsdeleteitem - returns the details (one record) from the ' jobtitle table ssql = "create proc procproductsdeleteitem(@productid long) as " _ & "delete from products where productid = @productid;" createstoredproc(ssql) ' procproductsadditem - add one record to the jobtitle table ssql = "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 table ssql = "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 procedures sub createstoredproc(byval ssql as string) dim con as oledbconnection dim 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 = con cmd.commandtext = ssql con.open() cmd.executenonquery() con.close() end subend module
(未完待续)
新闻热点
疑难解答
图片精选