程序思想:用SELECT name From sysobjects WHERE xtype = u得到所有表然后循环打开表根据Rs_ColumsFields(I)Name 得到字段名FieldType(Rs_ColumsFields(I)Type)得到字段类型Rs_ColumsFields(I)DefinedSize宽度
由于Rs_ColumsFields(I)Type返回类型是数字程序中写了一个FieldType函数转化成中文类型
Private Sub Command_Click()
Dim Cn As New ADODBConnection
Dim Rs_Table As New ADODBRecordset
Dim Rs_Colums As New ADODBRecordset
With Cn 定义连接
CursorLocation = adUseClient
Provider = sqloledb
Properties(Data Source)Value = LIHG
Properties(Initial Catalog)Value = NorthWind
Properties(User ID) = sa
Properties(Password) = sa
Properties(prompt) = adPromptNever
ConnectionTimeout =
Open
If State = adStateOpen Then
Rs_TableCursorLocation = adUseClient 得到所有表名
Rs_TableOpen SELECT name From sysobjects WHERE xtype = u Cn adOpenDynamic adLockReadOnly
Rs_TableMoveFirst
Do While Not Rs_TableEOF
DebugPrint Rs_TableFields(name)
Rs_ColumsCursorLocation = adUseClient
Rs_ColumsOpen select top * from [ & Rs_TableFields(name) & ] Cn adOpenStatic adLockReadOnly
For I = To Rs_ColumsFieldsCount 循环所有列
DebugPrint Rs_ColumsFields(I)Name 字段名
DebugPrint FieldType(Rs_ColumsFields(I)Type)字段类型
DebugPrint Rs_ColumsFields(I)DefinedSize宽度
Next
Rs_ColumsClose
Rs_TableMoveNext
Loop
Rs_TableClose
Set Rs_Colums = Nothing
Set Rs_Table = Nothing
Else
MsgBox 数据库连接失败请找系统管理员进行检查 ! cProgramName
End
End If
End With
End Sub
*********************************************************
* 名称FieldType
* 功能返回字段类型
* 用法FieldType(nType as integer)
*********************************************************
Function FieldType(nType As Integer) As String
Select Case nType
Case
FieldType = BINARY
Case
FieldType = BIT
Case
FieldType = CHAR
Case
FieldType = DATETIME
Case
FieldType = DECIMAL
Case
FieldType = FLOAT
Case
FieldType = IMAGE
Case
FieldType = INT
Case
FieldType = MONEY
Case
FieldType = NCHAR
Case
FieldType = NTEXT
Case
FieldType = NUMERIC
Case
FieldType = NVARCHAR
Case
FieldType = REAL
Case
FieldType = SMALLDATETIME
Case
FieldType = SMALLMONEY
Case
FieldType = TEXT
Case
FieldType = TIMESTAMP
Case
FieldType = TINYINT
Case
FieldType = UNIQUEIDENTIFIER
Case
FieldType = VARBINARY
Case
FieldType = VARCHAR
Case
FieldType =
End Select
End Function
此程序只是一个雏形可以在此基础上开发成一个工具使用
本程序在VB SQL SERVER 下运行通过
注程序中须引用ActiveX Data Objects (ADO)