机房收费-查询-查看学生余额

      最近在敲机房的查看学生余额,虽然看到很多人的对象窗口,知道怎么弄“舞台”上的东西,可是“幕后”的东西一点头绪都没有,一行代码的思路都没有。

   

              

      

      经过看小伙伴的机房给我的启示,突然发现怎么如此的简单。自己怎么都没有想到和学生的代码没有什么差别啊!

      定义-判断语句-查询语句-给文本框赋值(优化的地方:限制文本框的输入只能为数字)

 

代码:

 

Dim mrc As ADODB.Recordset '建立数据库连接
Dim txtSQL As String
Dim msgtext As String

 

Private Sub cmdinquire_Click()
    If Text1.Text = "" Then '判断是否输入了卡号
        MsgBox "请输入卡号!", vbOKOnly + vbExclamation, "温馨提示"
   
    End If
    
    txtSQL = "select * from student_info where cardno = '" & Text1.Text & "'" '调出SQL语句
    Set mrc = executeSQL(txtSQL, msgtext) '执行查询语句
    
    If mrc.EOF = True Then '判断记录集是否存在
        MsgBox "此卡号不存在!", vbOKOnly + vbExclamation, "温馨提示!"
        Text1.Text = ""
        
        txtClass.Text = "" '所有的文本框清空
        txtSex.Text = ""
        txtGrade.Text = ""
        txtMaigar.Text = ""
        txtMoney.Text = ""
        txtname.Text = ""
        txtother.Text = ""
        txtstuNo.Text = ""
        txtType.Text = ""
        
        Text1.SetFocus '控件获得焦点???
        Exit Sub
    End If
    
    
     '在相应的文本框中添加信息
     
        
        txtstuNo.Text = mrc.Fields(1)
        txtname.Text = mrc.Fields(2)
        txtSex.Text = mrc.Fields(3)
        txtGrade.Text = mrc.Fields(5)
        txtClass.Text = mrc.Fields(6)
        txtother.Text = mrc.Fields(8)
        txtMaigar.Text = mrc.Fields(4)
        txtType.Text = mrc.Fields(14)
        txtMoney.Text = mrc.Fields(7)
        
        
        
        txtstuNo.Enabled = False
        txtname.Enabled = False
        txtSex.Enabled = False
        txtGrade.Enabled = False
        txtClass.Enabled = False
        txtother.Enabled = False
        txtMaigar.Enabled = False
        txtType.Enabled = False
        txtMoney.Enabled = False
    
End Sub

 

Private Sub Text1_KeyPress(KeyAscii As Integer)
    If KeyAscii < 48 Or KeyAscii > 57 Then '限制文本框只能输入数字
        KeyAscii = 0
    End If
End Sub

 

 

 

 

 

总结查询窗体:

 

*核心的部分是从数据库调出来东西

 

  txtSQL = "select * from student_info where cardno = '" & Text1.Text & "'" '调出SQL语句
    Set mrc = executeSQL(txtSQL, msgtext) '执行查询语句 txtSQL = "select * from student_info where cardno = '" & Text1.Text & "'" '调出SQL语句
    Set mrc = executeSQL(txtSQL, msgtext) '执行查询语句


 

 

*给相应的文本框输入数据库中的信息

 

        txtstuNo.Text = mrc.Fields(1)
        txtname.Text = mrc.Fields(2)
        txtSex.Text = mrc.Fields(3)
        txtGrade.Text = mrc.Fields(5)
        txtClass.Text = mrc.Fields(6)
        txtother.Text = mrc.Fields(8)
        txtMaigar.Text = mrc.Fields(4)
        txtType.Text = mrc.Fields(14)
        txtMoney.Text = mrc.Fields(7) txtstuNo.Text = mrc.Fields(1)
        txtname.Text = mrc.Fields(2)
        txtSex.Text = mrc.Fields(3)
        txtGrade.Text = mrc.Fields(5)
        txtClass.Text = mrc.Fields(6)
        txtother.Text = mrc.Fields(8)
        txtMaigar.Text = mrc.Fields(4)
        txtType.Text = mrc.Fields(14)
        txtMoney.Text = mrc.Fields(7)

 

 

 

小伙伴们有什么更好的想法和优化的地方,欢迎在下边评论咯!

  

                                

 

 

 

 

 

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 21
    评论
评论 21
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

草莓味少女vv

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值