VB数据库设计实例
发布网友
发布时间:2022-05-02 01:55
我来回答
共3个回答
热心网友
时间:2022-06-26 13:57
'使用方法,在打开窗体时用opendb即可,关闭用closedb,数据库文件你修改dbname变量'表操作 打开 openrs 1,"select * from ..." 关闭 closers 1我写了四个表操作变量,1234,你自己看着理解,你要会SQl语句,要不这也没有什么用。'数据库连接:放在一个模块里里面
Public Const DBName = "FoxData.mdb"
Public Const DBpass = ""
Public conn As New ADODB.Connection
Public Rs1 As New ADODB.Recordset
Public Rs2 As New ADODB.Recordset
Public Rs3 As New ADODB.Recordset
Public Rs4 As New ADODB.RecordsetPublic Sub OpenDB()
Dim DBpath As String
DBpath = App.Path + "\" + DBName
conn.Open "provider=Microsoft.Jet.oledb.4.0;data source=" & DBpath & ";Jet OLEDB:Database Password=" & DBpass & ";"
End Sub
'******************************************
'关闭数据库
Public Sub CloseDB()
On Error Resume Next
conn.Close
Set conn = Nothing
End SubPublic Sub OpenRs(ByVal RsNum As Integer, ByVal RsSql As String)
Select Case RsNum
Case 1: Rs1.Open RsSql, conn, adOpenKeyset, adLockPessimistic
Case 2: Rs2.Open RsSql, conn, adOpenKeyset, adLockPessimistic
Case 3: Rs3.Open RsSql, conn, adOpenKeyset, adLockPessimistic
Case 4: Rs4.Open RsSql, conn, adOpenKeyset, adLockPessimistic
End SelectEnd Sub
Public Sub CloseRs(ByVal RsNum As Integer)
Select Case RsNum
Case 1: Rs1.Close: Set Rs1 = Nothing
Case 2: Rs2.Close: Set Rs2 = Nothing
Case 3: Rs3.Close: Set Rs3 = Nothing
Case 4: Rs4.Close: Set Rs4 = Nothing
End Select
End Sub
热心网友
时间:2022-06-26 13:58
在工程1时,设计一个数据库查询程序
在窗体放置3个TEXT控件,在TEXT1空间输入id是,另外2个控件能显示出id所对应的名称和性别
建一个名为data.mdb的ACCESS数据库,表名为user
字段1 id 主键
字段2 名称
字段3 性别Private Sub CmdFind_click() '查找按钮
Dim MyCnn As New ADODB.Connection
Dim MyRs As New ADODB.Recordset
MyCnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\My Documents\data.mdb;Persist Security Info=False"
MyRs.open "Select * from User where id=" & Text1.text ,MyCnn
if not MyRs.eof then
Text2.text=trim(rs!名称)
Text3.text=trim(rs!性别)
Else
Msgbox "没有该用户!"
Text1.selstart=0
Text1.SelLength=Len(Text1.Text)
Text1.SetFcous
EndIf
Myrs.close
Set MyRs=nothing
MyCnn.close
Set MyCnn=Nothing
End Sub
热心网友
时间:2022-06-26 13:58
我可以给你个实例。。。