📄 form3.frm
字号:
VERSION 5.00
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "Comdlg32.ocx"
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Object = "{CDE57A40-8B86-11D0-B3C6-00A0C90AEA82}#1.0#0"; "MSDATGRD.OCX"
Object = "{67397AA1-7FB1-11D0-B148-00A0C922E820}#6.0#0"; "MSADODC.OCX"
Begin VB.Form Form1
Caption = "数据库数据更新演示原程序 - 原作者:风云舞(http://www.lshdic.com)"
ClientHeight = 6930
ClientLeft = 60
ClientTop = 345
ClientWidth = 9720
LinkTopic = "Form1"
ScaleHeight = 6930
ScaleWidth = 9720
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command2
Caption = "Command2"
Height = 255
Left = 4800
TabIndex = 3
Top = 120
Width = 735
End
Begin MSComDlg.CommonDialog d
Left = 2640
Top = 2400
_ExtentX = 847
_ExtentY = 847
_Version = 393216
End
Begin MSDataGridLib.DataGrid edit
Bindings = "Form3.frx":0000
Height = 6315
Left = 120
TabIndex = 2
Top = 480
Width = 9570
_ExtentX = 16880
_ExtentY = 11139
_Version = 393216
AllowUpdate = -1 'True
HeadLines = 1
RowHeight = 15
AllowDelete = -1 'True
BeginProperty HeadFont {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "宋体"
Size = 9
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "宋体"
Size = 9
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ColumnCount = 2
BeginProperty Column00
DataField = ""
Caption = ""
BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED}
Type = 0
Format = ""
HaveTrueFalseNull= 0
FirstDayOfWeek = 0
FirstWeekOfYear = 0
LCID = 2052
SubFormatType = 0
EndProperty
EndProperty
BeginProperty Column01
DataField = ""
Caption = ""
BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED}
Type = 0
Format = ""
HaveTrueFalseNull= 0
FirstDayOfWeek = 0
FirstWeekOfYear = 0
LCID = 2052
SubFormatType = 0
EndProperty
EndProperty
SplitCount = 1
BeginProperty Split0
BeginProperty Column00
EndProperty
BeginProperty Column01
EndProperty
EndProperty
End
Begin VB.ComboBox list1
Enabled = 0 'False
Height = 300
Left = 2100
Style = 2 'Dropdown List
TabIndex = 1
Top = 105
Width = 2010
End
Begin VB.CommandButton Command1
Caption = "打开数据库"
Height = 330
Left = 105
TabIndex = 0
Top = 105
Width = 1905
End
Begin MSAdodcLib.Adodc ldc
Height = 330
Left = 7875
Top = 105
Visible = 0 'False
Width = 1800
_ExtentX = 3175
_ExtentY = 582
ConnectMode = 0
CursorLocation = 3
IsolationLevel = -1
ConnectionTimeout= 15
CommandTimeout = 30
CursorType = 3
LockType = 3
CommandType = 1
CursorOptions = 0
CacheSize = 50
MaxRecords = 0
BOFAction = 0
EOFAction = 0
ConnectStringType= 1
Appearance = 1
BackColor = -2147483643
ForeColor = -2147483640
Orientation = 0
Enabled = -1
Connect = ""
OLEDBString = ""
OLEDBFile = ""
DataSourceName = ""
OtherAttributes = ""
UserName = ""
Password = ""
RecordSource = ""
Caption = "Adodc1"
BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "宋体"
Size = 9
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
_Version = 393216
End
Begin MSComctlLib.ImageList ImageList1
Left = 3360
Top = 3885
_ExtentX = 1005
_ExtentY = 1005
BackColor = -2147483643
ImageWidth = 32
ImageHeight = 32
MaskColor = 12632256
_Version = 393216
BeginProperty Images {2C247F25-8591-11D1-B16A-00C0F0283628}
NumListImages = 1
BeginProperty ListImage1 {2C247F27-8591-11D1-B16A-00C0F0283628}
Picture = "Form3.frx":0012
Key = ""
EndProperty
EndProperty
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim dataname As String
'本程序着重演示ADO读取数据库基本信息,用Adodc、DataGrid控件控制及编辑数据库中的数据
'本程序为作者即将参加工作之前制作,目的为了充当工作参考资料,并散布网络启蒙此后各位VB同仁
'使用ADO,可以单击“工程”-“引用”-“Microsoft ActiveX Data Objects 2.0 Library”
Private Sub Command2_Click()
Form2.Show
End Sub
Private Sub Form_Load()
Set link1 = New ADODB.Connection '创建ADO连接
link1.Open "Provider=Microsoft.Jet.OLEDB.4.0;data source=" & "D:\Alice\my_src\数据库编辑程序\test.mdb"
Set tables = link1.OpenSchema(adSchemaColumns) '创建数据库记录集为了得到数据库中所有表名
oldtablename = ""
Do While Not tables.EOF
If tables("table_name") <> oldtablename Then
oldtablename = tables("table_name"): list1.AddItem oldtablename
End If
tables.MoveNext
Loop
If list1.ListCount = 0 Then MsgBox "数据库打开失败,或数据库不存在表", vbCritical, "错误": Exit Sub
dataname = "D:\Alice\my_src\数据库编辑程序\test.mdb"
list1.Enabled = True:
list1.ListIndex = 0:
'ldc控件连接数据源
ldc.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;data source=D:\Alice\my_src\数据库编辑程序\test.mdb;Persist Security Info=False"
'ldc控件使用SQL命令,GET数据源数据
ldc.RecordSource = "select * from " & list1.Text
ldc.Refresh
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -