这是动网论坛压缩access数据库的代码,请问这一句Set Engine = CreateObject("JRO.JetEngine")在asp.net里面怎么写?JRO.JetEngine这个东西好象在.net里面不存在,请问他在.net里面的相应代码是什么?我要的是压缩access,sql server 2000的压缩代码就免了。这个代码在.net又该怎么写?
Engine.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & "temp.mdb", _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & "temp1.mdb"----------------------------------------------------------------------------------
Function CompactDB(dbPath, boolIs97)
Dim fso, Engine, strDBPath,JET_3X
strDBPath = left(dbPath,instrrev(DBPath,"\"))
Set fso = CreateObject("Scripting.FileSystemObject")If fso.FileExists(dbPath) Then
fso.CopyFile dbpath,strDBPath & "temp.mdb"
Set Engine = CreateObject("JRO.JetEngine") If boolIs97 = "True" Then
Engine.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & "temp.mdb", _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & "temp1.mdb;" _
& "Jet OLEDB:Engine Type=" & JET_3X
Else
Engine.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & "temp.mdb", _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & "temp1.mdb"
End Iffso.CopyFile strDBPath & "temp1.mdb",dbpath
fso.DeleteFile(strDBPath & "temp.mdb")
fso.DeleteFile(strDBPath & "temp1.mdb")
Set fso = nothing
Set Engine = nothing CompactDB = "你的数据库, " & dbpath & ", 已经压缩成功!" & vbCrLfElse
CompactDB = "数据库名称或路径不正确. 请重试!" & vbCrLf
End IfEnd Function

解决方案 »

  1.   

    access数据库用久就会变得很大,可是如果从服务器下载到客户段端压缩再上传的话,又很麻烦,所以请高手帮我解决这个问题。最好有压缩access的代码!在这里谢谢大家了!
      

  2.   

    Imports System.Data.Odbc其他跟连数据库一样呀也就是采用连接。NET的连接数据库,然后取数据呀
      

  3.   

    Engine.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & "temp.mdb", _
    "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & "temp1.mdb"----------------------------------------------------------------------------------也就是连接数据库的字符串呀
      

  4.   

    fso.CopyFile strDBPath & "temp1.mdb",dbpath
    fso.DeleteFile(strDBPath & "temp.mdb")
    fso.DeleteFile(strDBPath & "temp1.mdb")
    Set fso = nothing
    Set Engine = nothing
    。net
    好象是FILE把
      

  5.   

    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;
    using ICSharpCode.SharpZipLib.Zip;namespace OA
    {
    /// <summary>
    /// WebForm1 的摘要说明。
    /// </summary>
    public class WebForm1 : System.Web.UI.Page
    {
      public string ServerDir;
      private void Page_Load(object sender, System.EventArgs e)
      {
        // 在此处放置用户代码以初始化页面
         this.ServerDir = Page.MapPath(".");
         this.ZipFile("01.txt*02.txt*000.zip");  //只是示例,具体的大家自己去实现
         this.ZipFile("01.txt*02.txt*001.zip");
         this.UnZipFile("000.zip*001.zip");
      }   #region Web Form Designer generated code
       override protected void OnInit(EventArgs e)
       {
        // CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
        InitializeComponent();
        base.OnInit(e);
        }
         /// <summary>
         /// 设计器支持所需的方法 - 不要使用代码编辑器修改
         /// 此方法的内容。
         /// </summary>
      private void InitializeComponent()
      {    
        this.Load += new System.EventHandler(this.Page_Load);
      }
       #endregion//压缩文件 p 为客户端传回来的文件列表:文件名+压缩包的名称
      public void ZipFile(string p)
      {
       string[] tmp = p.Split(new char[]{'*'});  //分离文件列表
       if(tmp[tmp.Length-1]!="")  //压缩包名称不为空
        {
          ZipOutputStream u = new ZipOutputStream(File.Create(ServerDir+tmp[tmp.Length-1]));            //新建压缩文件流 “ZipOutputStream”
          for(int i =0;i<tmp.Length-1;i++)
          {
    if(tmp[i]!="")  //分离出来的文件名不为空
    {
      this.AddZipEntry(tmp[i],u,out u); //向压缩文件流加入内容
    }
           }
           u.Finish(); // 结束压缩
           u.Close();
         }
      }//添加压缩项目:p 为需压缩的文件或文件夹; u 为现有的源ZipOutputStream;  out j为已添加“ZipEntry”的“ZipOutputStream”
    public void AddZipEntry(string p,ZipOutputStream u,out ZipOutputStream j)
     {
       string s =ServerDir+p;   if(Directory.Exists(s))  //文件夹的处理
       {
         DirectoryInfo di = new DirectoryInfo(s);
         foreach(DirectoryInfo tem in di.GetDirectories())  //获取子目录
          {
            ZipEntry z = new ZipEntry(this.ShortDir(tem.FullName)+"\\"); //末尾“\\”用于文件夹的标记
             u.PutNextEntry(z);    //此句不可少,否则空目录不会被添加
    s = this.ShortDir(tem.FullName);
    this.AddZipEntry(s,u,out u);       //递归
           }
          foreach(FileInfo temp in di.GetFiles())  //获取此目录的文件
           {
    s = this.ShortDir(temp.FullName);
    this.AddZipEntry(s,u,out u);      //递归
           }
         }
         else if(File.Exists(s))  //文件的处理
         {
           u.SetLevel(9);      //压缩等级
           FileStream f = File.OpenRead(s);
           byte[] b = new byte[f.Length];
           f.Read(b,0,b.Length);          //将文件流加入缓冲字节中
           ZipEntry z = new ZipEntry(this.ShortDir(s));
           u.PutNextEntry(z);             //为压缩文件流提供一个容器
           u.Write(b,0,b.Length);  //写入字节
           f.Close();
          }
          j=u;    //返回已添加数据的“ZipOutputStream”
      }public void UnZipFile(string p)   //解压缩
      {
       string[] un_tmp = p.Split(new char[]{'*'});
       int i2=0;  //防止名称冲突的参数
       for(int j=0;j<un_tmp.Length;j++)
       {
         if(un_tmp[j]!="")
         string un_time=System.DateTime.Now.ToShortDateString()+"-"+System.DateTime.Now.Hour.ToString()+"-"+System.DateTime.Now.Minute.ToString()+"-"+(System.DateTime.Now.Second+i2).ToString();
         string un_dir =ServerDir+"Unzip-"+un_time;
         Directory.CreateDirectory(un_dir);    //创建以解压时间为名称的文件夹
         ZipInputStream f = new ZipInputStream(File.OpenRead(ServerDir+un_tmp[j])); //读取压缩文件,并用此文件流新建 “ZipInputStream”对象A:  ZipEntry zp = f.GetNextEntry();   //获取解压文件流中的项目。 另注(我的理解):在压缩包里每个文件都以“ZipEntry”形式存在,其中包括存放文件的目录信息。如果空目录被压缩,该目录下将出现一个名称为空、大小为 0 、“Crc”属性为 00000000 的“文件”。此文件只是个标记,不会被解压。     while(zp!=null)
         {
          string un_tmp2;
          if(zp.Name.IndexOf("\\")>=0) //获取文件的目录信息
          {
    int tmp1 = zp.Name.LastIndexOf("\\");
    un_tmp2 = zp.Name.Substring(0,tmp1);
    Directory.CreateDirectory(un_dir+"\\"+un_tmp2+"\\"); //必须先创建目录,否则解压失败 --- (A) 关系到下面的步骤(B)
          }
          if(!zp.IsDirectory&&zp.Crc!=00000000L) //此“ZipEntry”不是“标记文件”
          {
            int i =2048;
    byte[] b = new byte[i];  //每次缓冲 2048 字节
             FileStream s= File.Create(un_dir+"\\"+zp.Name); //(B)-新建文件流
    while(true) //持续读取字节,直到一个“ZipEntry”字节读完
    {
      i = f.Read(b,0,b.Length); //读取“ZipEntry”中的字节
    if(i>0)
    {
      s.Write(b,0,i); //将字节写入新建的文件流
    }
    else
    {
      break; //读取的字节为 0 ,跳出循环
    }
           }
           s.Close();
          }
         goto A; //进入下一个“ZipEntry”
         }
         f.Close();
         i2++;
         }
        }
      }
     }
    }
      

  6.   

    http://www.ftponline.com/china/XmlFile.aspx?ID=278
      

  7.   

    JRO.JetEngine jet = JRO.JetEngineClass();
      

  8.   

    这里有个公开源码的C#压缩库:
    http://www.icsharpcode.net/OpenSource/NZipLib/default.asp
      

  9.   

    JRO.JetEngine jet = JRO.JetEngineClass();
    jet.CompactDatabase(sourceDBConnection, DestDBConnection);
      

  10.   

    to rickjelly2004(rick & jelly),我就是要在vb中压缩数据库呀。不过是vb.net罢了
      

  11.   

    to aoyo(遨游):
    错误如下:
    未定义类型JetEngine
      

  12.   

    难道各位就没有写过access数据库的压缩代码吗?只要你愿意发给我,200分我都愿意给!
      

  13.   

    所谓的fso是.net中的system.io.file这我知道,但是JRO.JetEngine 是什么东东我就不知道了!数据库备份,恢复我都解决了,就是不知道压缩怎么写。
      

  14.   

    添加引用:
    Microsoft Jet and Replication ObjectsC#:
    JRO.JetEngine jet = JRO.JetEngineClass();
    jet.CompactDatabase(sourceDBConnection, DestDBConnection);
      

  15.   

    JRO.JetEngine -- Microsoft Jet 数据库引擎
      

  16.   

    to aoyo(遨游),如何添加引用?
    添加引用:
    Microsoft Jet and Replication Objects
    ---------------------------------------
    写c#也没问题,c#我看得明白的!
      

  17.   

    如果不是用VS.Net的话,手动导入msjro
      

  18.   

    类型库导入 Tlbimp.exe
    1。tlbimp msjro.dll
    2。拷贝到你的Bin中
    3。程序中
    using 命名空间
      

  19.   

    msjro.dll应该在你的Program Files\Common Files\System\ado中