To read the VBScript code for an Access database package download _vbs

Source: Internet
Author: User
The effect is as shown in the figure:

Core code:
Copy Code code as follows:

Option Explicit
Dim arrtables (), I, Idxtables, Intvalidargs
Dim Blncontent, Blnfieldnames
Dim objconn, objFSO, objRS, Objschema
Dim strconnect, Strheader, Stroutput
Dim strfile, Strresult, strSQL, strtable
Const adSchemaTables = 20
' Check command line arguments
With WScript.Arguments
If. Unnamed.count = 1 Then
strfile =. Unnamed (0)
Else
Syntax
End If
Blnfieldnames = True
Blncontent = True
If. Named.count > 0 Then
Intvalidargs = 0
If. Named.exists ("T") Then
Blnfieldnames = False
Blncontent = False
Intvalidargs = Intvalidargs + 1
End If
If. Named.exists ("TF") Then
Blncontent = False
Intvalidargs = Intvalidargs + 1
End If
If Intvalidargs <>. Named.count Then Syntax
End If
End With
' Check if ' specified database file exists
Set objFSO = CreateObject ("Scripting.FileSystemObject")
If not objfso.fileexists (strfile) Then Syntax
Set objFSO = Nothing
' Connect to the Ms-access database
Set objconn = CreateObject ("ADODB. Connection ")
strconnect = "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" & strfile
objConn.Open strconnect
' Search for user tables and lists them in an array
Set Objschema = Objconn.openschema (adSchemaTables)
Idxtables =-1
Do as not objschema.eof
If ObjSchema.Fields.Item (3). Value = "TABLE" Then
Idxtables = idxtables + 1
ReDim Preserve arrtables (idxtables)
Arrtables (idxtables) = ObjSchema.Fields.Item (2). Value
End If
Objschema.movenext
Loop
' List all tables, their column names and their contents
For each strtable in Arrtables
strSQL = "SELECT * from" & strtable
Set objRS = objConn.Execute (strSQL)
If IsObject (objRS) Then
' Display ' the current table ' s name
If blncontent Then
WScript.Echo "" "Table: & strtable &" ""
Else
WScript.Echo "" "" & Strtable & "" "
End If
If Blnfieldnames Then
Stroutput = ""
Do as Not objrs.eof
' Create a header line with the ' column names and data types
Strheader = ""
For i = 0 to Objrs.fields.count-1
Strheader = Strheader & "," "[" _
& Getdatatypedesc (ObjRS.Fields.Item (i). Type) & "]" _
& ObjRS.Fields.Item (i). Name & "" "" "" "
Next
Strheader = Mid (Strheader, 2)
If blncontent Then
' List of the fields of the ' current record in comma delimited format
strresult = ""
For i = 0 to Objrs.fields.count-1
strresult = strresult & "," "" & ObjRS.Fields.Item (i). Value & "" "" "" "
Next
' Add ' The current record to the output string
Stroutput = stroutput & Mid (Strresult, 2) & VbCrLf
End If
' Next record
Objrs.movenext
Loop
' List the results for the ' current table
WScript.Echo Strheader & VbCrLf & Stroutput & VbCrLf
End If
End If
Next
Objrs.close
Objschema.close
Objconn.close
Set objRS = Nothing
Set Objschema = Nothing
Set objconn = Nothing
Function Getdatatypedesc (Mytypenum)
Dim arrtypes (8192), I
For i = 0 to UBound (arrtypes)
Arrtypes (i) = "????"
Next
Arrtypes (0) = "Empty"
Arrtypes (2) = "SmallInt"
Arrtypes (3) = "Integer"
Arrtypes (4) = "single"
Arrtypes (5) = "Double"
Arrtypes (6) = "Currency"
Arrtypes (7) = "Date"
Arrtypes (8) = "BSTR"
Arrtypes (9) = "IDispatch"
Arrtypes (+) = "Error"
Arrtypes (one) = "Boolean"
Arrtypes (a) = "Variant"
Arrtypes (+) = "IUnknown"
Arrtypes = "Decimal"
Arrtypes = "TinyInt"
Arrtypes (km) = "Unsignedtinyint"
Arrtypes (km) = "Unsignedsmallint"
Arrtypes = "Unsignedint"
Arrtypes = "BigInt"
Arrtypes = "Unsignedbigint"
Arrtypes (+) = "FILETIME"
Arrtypes (+) = "GUID"
Arrtypes (128) = "Binary"
Arrtypes (129) = "Char"
Arrtypes (130) = "WChar"
Arrtypes (131) = "Numeric"
Arrtypes (132) = "UserDefined"
Arrtypes () = "DBDate"
Arrtypes (134) = "DBTime"
Arrtypes (135) = "Dbtimestamp"
Arrtypes (136) = "Chapter"
Arrtypes (138) = "Propvariant"
Arrtypes (139) = "VarNumeric"
Arrtypes = "VarChar"
Arrtypes (201) = "LongVarChar"
Arrtypes () = "Varwchar"
Arrtypes (203) = "LongVarWChar"
Arrtypes (204) = "VarBinary"
Arrtypes (205) = "LongVarBinary"
Arrtypes (8192) = "Array"
Getdatatypedesc = Arrtypes (mytypenum)
End Function
Sub Syntax
Dim STRMSG
STRMSG = STRMSG & VbCrLf _
& "Accessrd.vbs, Version 1.01" & vbCrLf _
& Display MS Access Database (user) tables and, optionally, their contents "_
& VbCrLf & VbCrLf _
& "Usage:cscript//nologo ACCESSRD. VBS access_db_file [/T |/tf] "_
& VbCrLf & VbCrLf _
& "Where:" "Access_db_file" "is a ms-access database file" & VbCrLf _
& "/T list table names only" & VbCrLf _
& "/TF list table and field names only" & VbCrLf _
& "(Default is List tables, field names and contents)" _
& VbCrLf & VbCrLf _
& "Written by Rob van der Woude" & VbCrLf _
& "Http://www.robvanderwoude.com"
WScript.Echo STRMSG
Wscript.Quit (1)
End Sub

How to use:
Accessrd.vbs, Version 1.01Display MS Access Database (user) tables and, optionally, their contents
Usage:cscript//nologo ACCESSRD. VBS access_db_file [/T |/TF]where: "Access_db_file" is a ms-access database file
/T List table names only
/TF List table and field names only
(Default is List tables, field names and contents) Written by Rob van der Woudehttp://www.robvanderwoude.com

Test Code package download

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.