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

首頁 > 編程 > .NET > 正文

用vb.net操作access存儲過程(2)

2024-07-10 13:02:50
字體:
供稿:網(wǎng)友
在第一部分,我們已經(jīng)知道了如何利用ado.net和vb.net建立access中的存儲過程,這篇我們需要了解如何利用這些已經(jīng)建立好的存儲過程。
我們將程序做成公共類dbtier,這樣就可以在其他程序中調(diào)用了。
首先,幾個命名空間必不可少。
imports system
imports system.data
imports system.data.oledb
數(shù)據(jù)庫鏈接字符串
shared connectionstring as string = _    "provider=microsoft.jet.oledb.4.0;data source=c:/program " _    & "files/microsoft office/office10/samples/northwind.mdb"


productslist()返回dataset類型( 存儲過程執(zhí)行結(jié)果)
productsadditem()添加存儲過程參數(shù)
完整代碼:
imports system
imports system.data
imports system.data.oledb

' functions and subroutines for executing stored procedures in access.
public class dbtier

    ' change data source to the location of northwind.mdb on your local
    ' system.
    shared connectionstring as string = _
        "provider=microsoft.jet.oledb.4.0;data source=c:/program " _
        & "files/microsoft office/office10/samples/northwind.mdb"
    ' this function returns a dataset containing all records in
    ' the products table.
    function productslist() as dataset
        dim con as oledbconnection
        dim da as oledbdataadapter
        dim ds as dataset
        dim ssql as string


        ssql = "execute procproductslist"

        con = new oledbconnection(connectionstring)
        da = new oledbdataadapter(ssql, con)
        ds = new dataset()
        da.fill(ds, "products")

        return ds

    end function

    ' this function adds one record to the products table.
    sub productsadditem(byval productname as string, _
        byval supplierid as integer, byval categoryid as integer)
        dim con as oledbconnection
        dim cmd as oledbcommand = new oledbcommand()
        dim paramproductname as new oledbparameter()
        dim paramsupplierid as new oledbparameter()
        dim paramcategoryid as new oledbparameter()

        con = new oledbconnection(connectionstring)
        cmd.connection = con

        with paramproductname
            .parametername = "inproductname"
            .oledbtype = oledbtype.varchar
            .size = 40
            .value = productname
        end with
        cmd.parameters.add(paramproductname)

        with paramsupplierid
            .parametername = "insupplierid"
            .oledbtype = oledbtype.integer
            .size = 4
            .value = supplierid
        end with
        cmd.parameters.add(paramsupplierid)

        with paramcategoryid
            .parametername = "incategoryid"
            .oledbtype = oledbtype.integer
            .size = 4
            .value = categoryid
        end with
        cmd.parameters.add(paramcategoryid)

        cmd.commandtext = "execute procproductsadditem"
        con.open()
        cmd.executenonquery()
        con.close()

    end sub

    ' this function updates a specific jobtitle record with new data.
    sub productsupdateitem(byval productid as integer, _
        byval productname as string)
        dim con as oledbconnection
        dim cmd as oledbcommand = new oledbcommand()
        dim paramproductname as new oledbparameter()
        dim paramproductid as new oledbparameter()

        con = new oledbconnection(connectionstring)
        cmd.connection = con

        with paramproductid
            .parametername = "inproductid"
            .oledbtype = oledbtype.integer
            .size = 4
            .value = productid
        end with
        cmd.parameters.add(paramproductid)

        with paramproductname
            .parametername = "inproductname"
            .oledbtype = oledbtype.varchar
            .size = 40
            .value = productname
        end with
        cmd.parameters.add(paramproductname)

        cmd.commandtext = "execute procproductsupdateitem"
        con.open()
        cmd.executenonquery()
        con.close()

    end sub

    ' this function deletes one record from the products table.
    sub productsdeleteitem(byval productid as integer)
        dim con as oledbconnection
        dim cmd as oledbcommand = new oledbcommand()
        dim paramproductid as new oledbparameter()

        con = new oledbconnection(connectionstring)
        cmd.connection = con

        with paramproductid
            .parametername = "inproductid"
            .oledbtype = oledbtype.integer
            .size = 4
            .value = productid
        end with
        cmd.parameters.add(paramproductid)

        cmd.commandtext = "execute procproductsdeleteitem"
        con.open()
        cmd.executenonquery()
        con.close()

    end sub

end class國內(nèi)最大的酷站演示中心!
發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 响水县| 大兴区| 靖远县| 应用必备| 凌云县| 科技| 沧州市| 长春市| 兴安盟| 灵丘县| 独山县| 商城县| 桂阳县| 西宁市| 兴山县| 潞西市| 长子县| 保定市| 延寿县| 峡江县| 内黄县| 青岛市| 乐陵市| 临沭县| 育儿| 哈巴河县| 宁都县| 东丰县| 新津县| 光泽县| 车险| 庐江县| 石楼县| 彭山县| 时尚| 托克逊县| 阿拉善右旗| 夏河县| 苏州市| 佛学| 咸丰县|