功能实现很难 SQL中有两个表syscolumns和Sysobjects分别存的是字段名称,和表名 Select * From sysobjects Where type='U'会找出所有的表名 然后再去查列名 然后用Con创建 我只有这个方法了 抛砖引玉
SQL DMO啊,完全安裝SQL後,在安裝目錄下有示例代碼的。
vansoft(Vansoft Workroom ),能不能麻煩幫我貼一下代碼,謝謝!
For i = 0 To rs.Fields.Count - 1 With rs.Fields(i) Debug.Print .Name Debug.Print FieldType(.Type) Debug.Print .DefinedSize End With Next iPublic Function FieldType(intType As Integer) As String Select Case intType Case adChar FieldType = "adChar" Case adVarChar FieldType = "adVarChar" Case adSmallInt FieldType = "adSmallInt" Case adUnsignedTinyInt FieldType = "adUnsignedTinyInt" Case adDBTimeStamp FieldType = "adDBTimeStamp" End SelectEnd Function 'Find Primary key 'ADOX:Dim cat As New ADOX.Catalog Dim ndx As ADOX.Indexcat.ActiveConnection = "Provider=......"For Each ndx In cat.Tables(tablename).Indexes If ndx.PrimaryKey Then Debug.Print "Primary Key:" & ndx.Columns(0).Name Exit For End If Next
Select * From sysobjects Where type='U'会找出所有的表名 然后再去查列名
然后用Con创建
我只有这个方法了
抛砖引玉
With rs.Fields(i)
Debug.Print .Name
Debug.Print FieldType(.Type)
Debug.Print .DefinedSize
End With
Next iPublic Function FieldType(intType As Integer) As String Select Case intType
Case adChar
FieldType = "adChar"
Case adVarChar
FieldType = "adVarChar"
Case adSmallInt
FieldType = "adSmallInt"
Case adUnsignedTinyInt
FieldType = "adUnsignedTinyInt"
Case adDBTimeStamp
FieldType = "adDBTimeStamp"
End SelectEnd Function
'Find Primary key
'ADOX:Dim cat As New ADOX.Catalog
Dim ndx As ADOX.Indexcat.ActiveConnection = "Provider=......"For Each ndx In cat.Tables(tablename).Indexes
If ndx.PrimaryKey Then
Debug.Print "Primary Key:" & ndx.Columns(0).Name
Exit For
End If
Next