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

posted @ 2009-02-05 16:13  pensir  阅读(973)  评论(0编辑  收藏  举报