|
本帖最后由 walker 于 2014-4-23 11:45 编辑
根据这篇帖子(http://bbs.aardio.com/forum.php?mod=viewthread&tid=11931)整理,方便查阅。
建议将这两个功能扩展到库中哦。。
上代码:
- import access;
- import com;
- //打印access数据库中的所有表名
- //已排除系统表
- //walker
- PrintAllTableName = function(pathfile){
- var db = access(pathfile);
- if(!db){
- return false;
- }
-
- var cat = com.CreateObject("ADOX.Catalog")
- cat.ActiveConnection = db.connection;
- console.log(pathfile + '的表:');
- for index,tbl in ..com.each(cat.Tables) {
- if( tbl.Type = "TABLE") {
- console.log(tbl.Name);
- }
- }
-
- db.close();
- return true;
- }
- //打印access数据库中的所有表名
- //未排除系统表
- //qqmmcc
- PrintAllTableName_2 = function(pathfile){
- conn = com.CreateObject("ADODB.Connection")
- conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + pathfile;
- conn.open();
- rs = conn.OpenSchema("20")
-
- rs.MoveFirst()
- console.log(pathfile + '的表:');
- while(rs.EOF == false){
- console.log(rs("TABLE_NAME").value)
- rs.MoveNext()
- }
- }
- //打印所有字段名
- //alajia
- PrintAllFields = function(pathfile, tblname){
- var db = access(pathfile);
- if(!db){
- return false;
- }
-
- var cat = com.CreateObject("ADOX.Catalog");
- cat.ActiveConnection = db.connection;
- console.log(pathfile +'表' + tblname + '的字段:');
- for index,tbl in com.each(cat.Tables) {
- if( tbl.Type = "TABLE" && tbl.name == tblname){
- for(i=0; tbl.Columns.Count-1 ; 1){ //注意:从0开始
- console.log(tbl.Columns(i).Name); //列出表头
- }
- }
- }
- }
- import console;
- PrintAllTableName("D:\test.mdb");
- PrintAllTableName_2("D:\test.mdb");
- PrintAllFields("D:\test.mdb", "testTable");
- console.pause() //按任意键继续
- ;
复制代码 |
|