文章目录:
一:效果演示
二:实现思路
三:代码实现
form1
效果图
代码
form2
效果图
代码
form3
效果图
代码
一:效果演示
效果图◕‿◕✌✌✌
VB结合数据库实现-登录注册增删改查刷新
代码下载
数据库建表
外接程序——>可视化数据管理器
二:实现思路
建立数据库 外接程序——>可视化数据管理器——>文件——>新建——>Microsoft Access——>Version 7.0MDB ——>取名——>保存——>鼠标右键——>新建表——>生成表 对记录进行增删改查 选中表——>打开——>操作——>更新 连接数据库 data控件——>属性——>connect——>access ——>databasename需要连接数据库的名称——>选择我们自己建立的数据库 ——>recordsettype——>1-dynaset ——>recordsource记录源——>选择一张表 控件与数据库关联起来 属性 数据——>datasource——>数据控件data1 属性 数据——>datafield——>选择一张表
data组件方便查看数据 添加:AddNew 删除:Delete 修改:Edit 查 FindFirst〈条件字符串〉:在记录集中查找满足条件的第一条记录 FindLast 〈条件字符串〉:在记录集中查找满足条件的最后一条记录 FindNext〈条件字符串〉:从当前记录开始查找满足条件的下一条记录 FindPrevious〈条件字符串〉:从当前记录开始查找满足条件的上一条记录 刷新:Refresh
三:代码实现
form1
效果图
代码
Option Explicit Private Sub Command1_Click() If Text1.Text = 123 And Text2.Text = 123 Then Dim a1 As String a1 = MsgBox("恭喜您,登录成功!", vbExclamation, "提示") Form1.Visible = False Form3.Visible = True ElseIf Text1.Text = 456 And Text2.Text = 456 Then Dim a2 As String a2 = MsgBox("恭喜您,登录成功!", vbExclamation, "提示") Form1.Visible = False Form3.Visible = True ElseIf Text1.Text = 789 And Text2.Text = 789 Then Dim a3 As String a3 = MsgBox("恭喜您,登录成功!", vbExclamation, "提示") Form1.Visible = False Form3.Visible = True Else MsgBox ("密码错误!") End If End Sub Private Sub Form_Load() End Sub Private Sub Label4_Click() Form2.Visible = True Form1.Visible = False End Sub
form2
效果图
代码
Option Explicit Private Sub Command1_Click() If Text1.Text = 123 And Text2.Text = 123 Then Dim b1 As String b1 = MsgBox("恭喜您,注册成功!", vbExclamation, "提示") ElseIf Text1.Text = 456 And Text2.Text = 456 Then Dim b2 As String b2 = MsgBox("恭喜您,注册成功!", vbExclamation, "提示") ElseIf Text1.Text = 789 And Text2.Text = 789 Then Dim b3 As String b3 = MsgBox("恭喜您,注册成功!", vbExclamation, "提示") End If Form2.Visible = False Form1.Visible = True End Sub Private Sub Command2_Click() End End Sub Private Sub Form_Load() End Sub
form3
效果图
代码
Option Explicit Private Sub Command1_Click() With Data1.Recordset .AddNew .Fields("sno") = "6" .Fields("cno") = "c1" .Fields("score") = 97 .Update End With Form_Activate End Sub Private Sub Command2_Click() Data1.Recordset.Delete Form_Activate End Sub Private Sub Command3_Click() With Data1.Recordset .Edit .Fields("sno") = "6" .Fields("cno") = "c1" .Fields("score") = 100 .Update End With Form_Activate End Sub Private Sub Command4_Click() Data1.Refresh End Sub Private Sub Command5_Click() Data1.Recordset.FindFirst "sno='2'" End Sub Private Sub Command6_Click() Data1.Recordset.FindLast "sno='2'" End Sub Private Sub Command7_Click() Data1.Recordset.FindNext "sno='2'" End Sub Private Sub Command8_Click() Data1.Recordset.FindPrevious "sno='2'" End Sub Private Sub Form_Activate() Data1.Recordset.MoveLast Data1.Caption = "记录数为:" & Data1.Recordset.RecordCount Data2.Recordset.MoveLast Data2.Caption = "记录数为:" & Data2.Recordset.RecordCount Data3.Recordset.MoveLast Data3.Caption = "记录数为:" & Data3.Recordset.RecordCount End Sub