来源:SailAFly | 2006-12-23 | (有3701人读过)
引用外部组件: Mircosoft ActiveX Data Objects 2.5 Library
模块代码:
Option Explicit Public Conn As ADODB.Connection Public rs As ADODB.Recordset Public strDBFile As String
'#------------------------------------# '# 设置启动Main过程 # '#------------------------------------# Sub Main() strDBFile = GetAppPath & "DB_Art.mdb" Call ConnectDB(strDBFile) frmMain.Show End Sub
'#------------------------------------# '# 获取当前相对路径 # '#------------------------------------# Public Function GetAppPath() As String GetAppPath = App.Path & IIf(Len(App.Path) > 3, "\", "") End Function '#--------------------------# '# 数据库连接 # '#--------------------------# Public Sub ConnectDB(ByVal strDBFile As String) Set Conn = New ADODB.Connection Conn.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBFile & ";" End Sub
窗体代码:
'保存数据的过程 Private Function AddData() As Boolean Dim tRs As New ADODB.Recordset Dim sSql As String On Error GoTo Er sSql = "Select * From 表名称" tRs.Open sSql, Conn, 1, 2 tRs.AddNew
tRs("字段1") = Text1(0) tRs("字段2") = Text1(1)
tRs.Update tRs.Close Set tRs = Nothing MsgBox "数据入库成功!", vbOKOnly + vbInformation AddData = True Exit Function Er: AddData = False End Function
|