前言:
查询这块涉及到了几个窗体,有学生查看余额、学生查看上机记录、学生充值记录查询窗体、学生上机状态查看。
学生查看上机记录和学生充值记录查询窗体类似,在这里以充值记录为例
学生查看余额:
学生充值记录查询:
学生查看上机记录和学生查看余额的思路是一样的
遇到的问题及重点代码的学习:
& 和’ ” :
&是代码行的连接符号;例:S1 = “1234”,S2 = “ABCD”,令S = S1&S2 ,
则S = “1234ABCD”;
‘用来注释;
“a”表示a是一段字符串;其中”在”“内使用如何使文本框中字体变大:
很简单,在Form中编写代码,用FontSize属性;
例:txtCard.FontSize = txtCard.FontSize + 10
3.固定语句的顺序是不能颠倒的
例:
With MSHFlexGrid
Do While Not mrc.EOF
…
mrc.MoveNext
Loop
End With
mrc.Close
其中我把End With语句放在了Do While之前,就报错了,出现了
无效或不合格的引用这个错误;
4.实时错误 ‘-2147217887 (80040e21)’:多步操作产生错误;
原因是:大多数是输入的数据违反了数据库的约束条件、字段大小超过限制提交的数据个数、字段数据类型不匹配、自动编号指定了值、或者自动编号未作自动赋值、字段不允许为空值等。
另外检查你的外键约束之类的,如触发器,是否表无主键。
5.导出Excel 参考之前的博客:
http://blog.csdn.net/xsh096011/article/details/78522942
学生查看余额:
Private Sub cmdInquire_Click()
Dim mrc As ADODB.Recordset '定义数据集对象
Dim txtSQL As String '定义字符串变量,表示查询语句
Dim MsgText As String '定义字符串变量,返回查询语句
txtSQL = "select * from student_Info where student_Card = '" & Trim(txtCard.Text) & "'"
Set mrc = ExecuteSQL(txtSQL, MsgText)
If mrc.EOF Then
MsgBox "该卡号不存在或已不再使用!", vbOKOnly, "提示"
Else
txtStudentNo.Text = mrc.Fields(1) '将mrc.Fields(1)的数据赋值给txtStudentNo
txtName.Text = mrc.Fields(2)
txtSex.Text = mrc.Fields(3)
department.Text = mrc.Fields(4)
grade.Text = mrc.Fields(5)
class.Text = mrc.Fields(6)
status.Text = mrc.Fields(10)
explain.Text = mrc.Fields(8)
txtRecharge.Text = mrc.Fields(15)
End If
学生充值记录查询:
Private Sub cmdInquire_Click()
Dim txtSQL As String
Dim MsgText As String
Dim vbExcalmation As String
Dim mrc As ADODB.Recordset
If Trim(txtCard.Text) = "" Then
MsgBox "卡号不能为空", vbOKOnly, "提示"
End If
'组合SQL语句
txtSQL = "select * from money_Info where "
'组合查询语句
txtSQL = txtSQL & " money_Card = '" & Trim(txtCard.Text) & "'"
'查询所有满足条件的内容
txtSQL = txtSQL & " order by money_Card "
Set mrc = ExecuteSQL(txtSQL, MsgText)
'将查询内容显示在表格控件中
With MSHFlexGrid
.Rows = 2
.CellAlignment = 4
.TextMatrix(1, 0) = "卡号"
.TextMatrix(1, 1) = "姓名"
.TextMatrix(1, 2) = "充值金额"
.TextMatrix(1, 3) = "账户余额"
.TextMatrix(1, 4) = "充值日期"
.TextMatrix(1, 5) = "充值时间"
'判断是否移动到数据集对象的最后一条记录
Do While Not mrc.EOF
.Rows = .Rows + 1
.CellAlignment = 4
.TextMatrix(.Rows - 1, 0) = mrc.Fields(0)
.TextMatrix(.Rows - 1, 1) = mrc.Fields(1)
.TextMatrix(.Rows - 1, 2) = mrc.Fields(2)
.TextMatrix(.Rows - 1, 3) = mrc.Fields(3)
.TextMatrix(.Rows - 1, 4) = mrc.Fields(4)
.TextMatrix(.Rows - 1, 5) = mrc.Fields(5)
'移动到下一条记录
mrc.MoveNext
Loop
End With
mrc.Close
End Sub
Private Sub Form_Load()
txtCard.FontSize = txtCard.FontSize + 10
With MSHFlexGrid '初始化flexgrid控件的行标题
.CellAlignment = 4 'flexAlignCenter
.TextMatrix(1, 0) = "卡号"
.TextMatrix(1, 0) = "卡号"
.TextMatrix(1, 1) = "姓名"
.TextMatrix(1, 2) = "充值金额"
.TextMatrix(1, 3) = "账户余额"
.TextMatrix(1, 4) = "充值日期"
.TextMatrix(1, 5) = "充值时间"
End With
Me.Width = Screen.Width * 0.5
Me.Height = Screen.Height * 0.75
Left = 0 ' 在水平方向上居中显示。
Top = 0 ' 在垂直方向上居中显示。
End Sub