Me.Caption = Mid(Me.Caption, 1, InStr(Me.Caption, "表")) & "(共有" & Grid2.Rows - 1 & "条记录)"
'-----------------------------------------------------------
End Sub
(6)根据参数com和rs,向combobox中添加值
Public Sub fillcom1(com As ComboBox, rs As ADODB.Recordset)'填充combobox
com.Clear
If rs.RecordCount <= 0 Then Exit Sub
rs.MoveFirst
Do Until rs.EOF
com.AddItem (rs.Fields(0).Value) & ""
rs.MoveNext
Loop
rs.MoveFirst
End Sub
3.窗体的加载
Private Sub Form_Load()
' 给strsql变量赋值,值为SELECT语句,参考格式如下,只有字段名,字段无别名,这是为了与界面用户操作的查询字段同步,给编程者提供的字段名称
strsql = "SELECT STUDENT_TBL.STUID, STUDENT_TBL.STUname, STUDENT_TBL.STUsorce, STUDENT_TBL.STUchive FROM STUDENT_TBL"
' 给strdemand变量赋值,值为SELECT语句,参考格式如下,给字段取别名是为了在选择条件的界面给用户提供汉字的参考
strdemand = "SELECT STUDENT_TBL.STUID as 学号, STUDENT_TBL.STUname as 姓名, STUDENT_TBL.STUsorce as 课程, STUDENT_TBL.STUchive as 成绩 FROM STUDENT_TBL"
' 给strtable变量赋值,值为要查询的表名或视图名
strtable = "STUDENT_TBL"
strsumdemand = ""
Dim i As Integer
' --------------给Grid1初始化,设置列宽、单元格对齐方式
Grid1.FormatString = " 逻辑符|^ 列 名 |^ 运算符 |^ 数据值 |"
Grid1.ColWidth(4) = 0
Grid1.ColWidth(3) = 2500
Grid1.ColWidth(2) = 1000
Grid1.ColWidth(1) = 1850
Grid1.ColWidth(0) = 1000
For i = 0 To 3
Grid1.Row = 0
Grid1.Col = i
Grid1.CellAlignment = 4
Next i
' -----------------------------------------------------
Opencn '调用子过程Opencn,打开数据库连接
openrs strdemand '调用子过程Openrs,并传参数—查询的内容
' --------------------向Combo1(1)中添加strdemand字符串中字段别名
For i = 0 To rs.Fields.Count - 1
Combo1(1).AddItem rs.Fields(i).Name
Next i
' --------------------向Combo1(4)中添加strsql字符串中字段名
|