国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

用vb.net操作ms access存儲(chǔ)過程(1)

2024-07-10 13:02:50
字體:
供稿:網(wǎng)友
  • 本文來源于網(wǎng)頁設(shè)計(jì)愛好者web開發(fā)社區(qū)http://www.html.org.cn收集整理,歡迎訪問。
  • 1.存儲(chǔ)過程在access中如何運(yùn)行?
         不像access中的其他對(duì)象或者ms sql中可以有直觀的設(shè)計(jì)界面,在access中的存儲(chǔ)過程,沒有這些,所以我們不能在access中建立他們,我將向大家展示在ado.net中如何操作他們。
    2。創(chuàng)建存儲(chǔ)過程
        我們需要使用一段sql語句來創(chuàng)建存儲(chǔ)過程,我們使用事例數(shù)據(jù)庫northwind 來說明我們的例子。
        一個(gè)簡單的存儲(chǔ)過程
               "create proc procproductslist as select * from products;"
      create proc procproductslist 意思是創(chuàng)建存儲(chǔ)過程as 后面可以是任何有效的sql語句。
       但是有的時(shí)候我們需要制定某一參數(shù),比如我們要?jiǎng)h除指定productsid 的記錄,這時(shí)就需要這樣的存儲(chǔ)過程。"create proc procproductsdeleteitem(inproductsid long)" & _
    "as delete from products where productsid = inproductsid;" 在給出一個(gè)更復(fù)雜的:
    "create proc procproductsadditem(inproductname varchar(40), " & _
    "insupplierid long, incategoryid long) " & _
    "as insert into products (productname, supplierid, categoryid) " & _
    "values (inproductname, insupplierid, incategoryid);""create proc procproductsupdateitem(inproductid long, " & _
    "                                   inproductname varchar(40)) " & _
    "as update products set productname = inproductname " & _
    "    where productid = inproductid;"好了,原理已經(jīng)知道了。我們把這些綜合一下做一個(gè)模塊,豈不更好,說干就干。
    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
    (未完待續(xù))
    發(fā)表評(píng)論 共有條評(píng)論
    用戶名: 密碼:
    驗(yàn)證碼: 匿名發(fā)表
    主站蜘蛛池模板: 邵武市| 榆林市| 凉城县| 延津县| 将乐县| 虞城县| 大同市| 万宁市| 邳州市| 吉林省| 柘城县| 富阳市| 安丘市| 方山县| 体育| 定兴县| 嘉峪关市| 珲春市| 冷水江市| 留坝县| 莱阳市| 吉林省| 肇庆市| 沙河市| 灌南县| 宿松县| 沙湾县| 虞城县| 长宁县| 抚顺市| 奉贤区| 广州市| 衡阳市| 汉源县| 远安县| 龙泉市| 潼关县| 恭城| 饶平县| 长宁区| 汉阴县|