zoukankan      html  css  js  c++  java
  • Access存储过程,环境:VB 2005+.NET2.0+ACCESS2003(转载)

    简化程序,仅有创建读取查询,读取查询语句,


    创建存储过程模块CreateSP.vb
    =======================================================

    Imports System
    Imports System.Data
    Imports System.Data.OleDb

    Module CreateSP
    Sub Main()
    ProductsProcs()
    End Sub

    '为DB创建存储过程.
    Sub ProductsProcs()
    Dim sSQL As String

    '查询
    sSQL = "CREATE PROC procProductsList AS SELECT * FROM datas;"
    CreateStoredProc(sSQL)

    End Sub

    '创建
    Sub CreateStoredProc(ByVal sSQL As String)
    Dim con As OleDbConnection
    Dim cmd As OleDbCommand = New OleDbCommand
    Dim da As OleDbDataAdapter
    Dim sConStr As String = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=.\database.mdb"
    con = New OleDbConnection(sConStr)
    cmd.Connection = con
    cmd.CommandText = sSQL
    con.Open()
    cmd.ExecuteNonQuery()
    con.Close()
    End Sub
    End Module





    调用模块
    ===========================================================


    Imports System
    Imports System.Data
    Imports System.Data.OleDb

    Public Class DBTier

    Shared connectionString As String = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=.\database.mdb"


    '库存查询
    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, "datas")
    Return ds
    End Function

    End Class




    实例
    =================================================================

    Option Strict Off
    Option Explicit On
    Imports System.Data.SqlClient
    Imports System.Data.OleDb
    Imports System.Text

    Public Class manager

    Inherits System.Windows.Forms.Form
    Dim Stored As New DBTier
    Dim statusok As Boolean
    Dim frmStatusMessage As New status
    'Public Event TextChanged As EventHandler


    Private Sub manager_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load

    If Not statusok = True Then
    frmStatusMessage.Show("正在构建数据表,请稍候.")
    End If

    '建立表,只需执行一次.
    '----------------------------------------
    'ProductsProcs()
    End Sub

    Private Sub dbview_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dbview.Click
    dbdg.DataSource = Stored.ProductsList.Tables(0)
    End Sub

    End Class

  • 相关阅读:
    [mysql] information_schema数据库表
    Linux 进程操作_12
    Linux 标准输入输出_11
    apache2
    poj 3083 Children of the Candy Corn 夜
    poj 2151 Check the difficulty of problems 夜
    poj 3274 Gold Balanced Lineup 夜
    poj 3414 Pots 夜
    poj Finicky Grazers 3184 夜
    poj 3253 Fence Repair 夜
  • 原文地址:https://www.cnblogs.com/pyt5208/p/1384697.html
Copyright © 2011-2022 走看看