VB编程实例4(单个数据库表应用程序) 1.打开工程vblx,添加一个窗口Form1,修改Form1的属性,名称(Nam e)为:fxs,Caption(窗口标题)为: ,保存在你的目录下.在fm ain中添加水平菜单(m3):数据库,添加下拉菜单(m31): ,其单击代码为:fxs.Show 2.准备好access数据库xs.m db,有两个表xs,cj,在数据源中添加系统DSN,选择驱动程序为Microsoft Access Driver,名称为lx,数据库指向你的xs.m db 添加ADO部件(Mi crosoft ADO Data Control 6.0)和DataGrid 部件(Microsoft DataGrid Control 6.0). 3.在窗体上放一个框架Fram e1,去掉Caption,设BorderStyle为0-None,在Fram e1上放一个Fram e2, 去掉Caption,设BorderStyle为0-None,在Fram e2上放置Adodc1,设其ConnectionString属性为DNS=lx, RecordSource的命令类型为2-adCm dTable,表名为xs,在Fram e2上放置命令按钮数组Comm and1(0~3),Caption分别为:添加,保存,删除,关闭在Fram e1上放一个Fram e3,去掉Caption,在Fram e3上放置标签数组zdm(0~7),设置字体,颜, Caption分别为序号,登录名,姓名,性别,生日,,电话,住址,放置文本框数组zdz(0~7), DataSource为Adodc1,DataField分别为
datafield属性xh,dlm,xm,xb,sr,eml,dh,dz 4.在窗体上放一个DataGrid1,设其DataSource为Adodc1,右击DataGrid1选择检索字段, 再右击调出属性页,在通用页设置允许添加,删除,更新,在列页设置各列的标题分别为: 序号,登录名,姓名,性别,生日,,电话,住址,在布局页设置各列的宽和对齐方式5.响应Form的Load事件,添加如下代码: Left = (Screen.Width - Width) \ 2 Top = (Screen.Height - Height) \ 2'窗口居中 Fram e1.Left = 0: Fram e1.Top = 0 Fram e1.Width = ScaleWidth Fram e1.Height = ScaleHeight / 4 Fram e2.Left = (ScaleWidth -
Fram e2.Width) \ 2 Fram e3.Left = (ScaleWidth - Fram e3.Width) \ 2 DataGrid1.Top = ScaleHeight / 4: DataGrid1.Left = 0 DataGrid1.Width = ScaleWidth DataGrid1.Height = ScaleHeight * 3 / 4 Adodc1.Refresh 响应Form的Resize事件,添加如下代码: If WindowState = 1 Then Exit Sub'最小化时不执行代码If WindowState = 0 Then Left = (Screen.Width - Width) \ 2 Top = (Screen.Height - Height) \ 2'正常窗口居中End If Fram e1.Left = 0: Fram e1.Top = 0 Fram e1.Width = ScaleWidth Fram e1.Height = ScaleHeight / 4 Fram e2.Left = (ScaleWidth - Fram e2.Width) \ 2 Fram e3.Left = (ScaleWidth - Fram e3.Width) \ 2 DataGrid1.Top = ScaleHeight / 4: DataGrid1.Left = 0 DataGrid1.Width = ScaleWidth DataGrid1.Height = ScaleHeight * 3 / 4 响应Form的Unload事件,添加如下代码: Adodc1.Recordset.Close 响应Comm and1的Click事件Select Case Index Case 0 Adodc1.Recordset.AddNew Case 1 Adodc1.Recordset.Update Case 2 Adodc1.Recordset.Delete Case 3 Unload fxs End Select

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。