• VB编程实例(单个数据库表应用程序)

  • 2010-07-27 23:19 发表      系统分类:可编程逻辑      自定义分类:VB
  • 标签:VB编程 实例
 
1.打开工程vblx,添加一个窗口Form1,修改Form1的属性,名称(Name)为:fxs,Caption(窗口标题)为:
学生档案,保存在你的目录下.在fmain中添加水平菜单(m3):数据库,添加下拉菜单(m31):
学生档案,其单击代码为:fxs.Show
2.准备好access数据库xs.mdb,有两个表xs,cj,在数据源中添加系统DSN,选择驱动程序
为Microsoft Access Driver,名称为lx,数据库指向你的xs.mdb
添加ADO部件(Microsoft ADO Data Control 6.0)和DataGrid部件(Microsoft DataGrid Control 6.0).
3.在窗体上放一个框架Frame1,去掉Caption,设BorderStyle为0-None,在Frame1上放一个Frame2,
去掉Caption,设BorderStyle为0-None,在Frame2上放置Adodc1,设其ConnectionString属性为DNS=lx,
RecordSource的命令类型为2-adCmdTable,表名为xs,在Frame2上放置命令按钮数组
Command1(0~3),Caption分别为:添 加,保 存,删 除,关 闭
在Frame1上放一个Frame3,去掉Caption,在Frame3上放置标签数组zdm(0~7),设置字体,颜色,
Caption分别为序号,登录名,姓名,性别,生日,电子邮件,电话,住址,放置文本框数组zdz(0~7),
DataSource为Adodc1,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'窗口居中
Frame1.Left = 0: Frame1.Top = 0
Frame1.Width = ScaleWidth
Frame1.Height = ScaleHeight / 4
Frame2.Left = (ScaleWidth - Frame2.Width) \ 2
Frame3.Left = (ScaleWidth - Frame3.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
Frame1.Left = 0: Frame1.Top = 0
Frame1.Width = ScaleWidth
Frame1.Height = ScaleHeight / 4
Frame2.Left = (ScaleWidth - Frame2.Width) \ 2
Frame3.Left = (ScaleWidth - Frame3.Width) \ 2
DataGrid1.Top = ScaleHeight / 4:
DataGrid1.Left = 0
DataGrid1.Width = ScaleWidth
DataGrid1.Height = ScaleHeight * 3 / 4
响应Form的Unload事件,添加如下代码:
Adodc1.Recordset.Close
响应Command1的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
 

评论 VB编程实例(单个数据库表应用程序)