1,216
社区成员
发帖
与我相关
我的任务
分享
Dim cn As New ADODB.Connection, RS As New ADODB.Recordset
Private Sub KKK(cn)
cn.ConnectionString = "driver={SQL Server};server=.;uid=sa;pwd=;database=驾校管理"
cn.Open
End Sub
Private Sub Form_Load()
Label1.Caption = ""
Call KKK(cn)
Combo1.Clear
Set RS = cn.OpenSchema(adSchemaTables)
Do Until RS.EOF
If Left(RS!TABLE_NAME, 3) <> "sys" And Left(RS!TABLE_NAME, 3) <> "dtp" Then
Combo1.AddItem RS!TABLE_NAME '在 Combo1 加载所有用户数据表,不加载系统数据表
End If
RS.MoveNext
Loop
RS.Close
cn.Close
Label2.Visible = False
End Sub
Private Sub Combo1_Click()
Dim SSA As Integer, SQLA As String, PP As Integer, ZDM() As String, PP1 As Integer
Label1.Caption = "显示" & Combo1.Text & "数据表的所有数据"
Label2.Caption = ""
Label2.Visible = True
MSFlexGrid1.Clear
MSFlexGrid1.Visible = True
Call KKK(cn)
SQLA = "Select * From " & Combo1.Text
RS.Open SQLA, cn, 3, 2
SSA = RS.RecordCount
Set fld = RS.Fields
For Each fld In RS.Fields
PP = PP + 1 '得到字段的总数
Next
ReDim ZDM(1 To PP)
For Each fld In RS.Fields
PP1 = PP1 + 1
ZDM(PP1) = fld.Name '向 ZDM 数组中添加字段
Next
With MSFlexGrid1
.Cols = PP
.Rows = 1 + SSA
For I = 1 To PP
.TextMatrix(0, I - 1) = ZDM(I) '在 MSFlexGrid1 中添加标题,即字段名
Next I
For I = 1 To SSA
For J = 0 To PP - 1
.TextMatrix(I, J) = RS.Fields(J) '在 MSFlexGrid1 中添加内容,即显示数据
Next J
RS.MoveNext
Next I
End With
RS.Close
cn.Close
Label2.Caption = "“" & Combo1.Text & "”数据表有" & PP & "个字段,有" & SSA & "条记录!"
End Sub