导出DBF,并且提供下载

#region Declare

string mFilePath = MapPath("../DataTmp/");
                string mTableName = "WYKS";
                string mStrConn = @"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + mFilePath + @"/;Extended Properties=""dBASE IV;HDR=Yes;"";";

System.Data.OleDb.OleDbConnection mOLDBConn = new System.Data.OleDb.OleDbConnection(mStrConn);
                if (System.IO.File.Exists(mFilePath + "//" + mTableName + ".DBF") == true)
                {
                    System.IO.File.Delete(mFilePath + "//" + mTableName + ".DBF");
                }
                #endregion Declare

#region 创建DBF表文件

#region CREATE TABLE

string sqlt = "CREATE TABLE " + mTableName + "(" +
                    "KSH varchar(18)," +
                    "KSCJ varchar(1)," +
                    "KYZK varchar(1)," +
                    "YYYD varchar(1)" +
                    ")";
                System.Data.OleDb.OleDbCommand OLDBComm = new System.Data.OleDb.OleDbCommand(sqlt, mOLDBConn);
                mOLDBConn.Open();
                OLDBComm.ExecuteNonQuery();
                OLDBComm.Dispose();
                mOLDBConn.Close();

#endregion CREATE TABLE

#region Delete TableDate

System.Data.OleDb.OleDbCommand OLDBCommIn = new System.Data.OleDb.OleDbCommand("delete * from " + mTableName, mOLDBConn);
                mOLDBConn.Open();
                OLDBCommIn.ExecuteNonQuery();
                OLDBCommIn.Dispose();
                mOLDBConn.Close();

#endregion Delete TableDate

#endregion 创建DBF表文件

#region 导出数据到DBF

string mWhere = " 1=1";
                if (this.txtExamsPoint.Text.Length > 0)
                {
                    mWhere = mWhere + " And ExamsPoint = '" + this.txtExamsPoint.Text.Trim() + "'";

if (this.txtExaminationRoom.Text.Trim().Length > 0)
                    {
                        mWhere = mWhere + " And ExaminationRoom In(Select ExaminationRoom From T_ExaminationRoom Where ExaminationRoomName = '" + this.txtExaminationRoom.Text.Trim() + "' And ExamsPoint = '" + this.txtExamsPoint.Text.Trim() + "')";
                    }
                }
                if (this.txtKSHStart.Text.Trim().Length > 0)
                {
                    mWhere = mWhere + " And KSH >= '" + this.txtKSHStart.Text.Trim() + "'";
                }
                if (this.txtKSHEnd.Text.Trim().Length > 0)
                {
                    mWhere = mWhere + " And KSH <= '" + this.txtKSHEnd.Text.Trim() + "'";
                }

System.Data.DataSet mDSOralAcademic = new System.Data.DataSet();
                OralExam.Entity.T_OralAcademic mEOralAcademic = new OralExam.Entity.T_OralAcademic();

mEOralAcademic.WhereCondition = mWhere;

OralExam.Data.T_OralAcademic.pro_T_OralAcademic_SelectDynamic(mEOralAcademic, ref mDSOralAcademic, OralExam.BaseC.GlobeValues.ConnString);

for (int i = 0; i < mDSOralAcademic.Tables[0].Rows.Count; i++)
                {
                    mEOralAcademic = OralExam.DataToEntity.T_OralAcademic.GetEntity(mDSOralAcademic, i);

string mSqlExport = "Insert Into " + mTableName + "(KSH,KSCJ,KYZK,YYYD)";
                    mSqlExport = mSqlExport + " Select ";
                    mSqlExport = mSqlExport + "'" + mEOralAcademic.KSH + "' as KSH,";
                    mSqlExport = mSqlExport + "'" + mEOralAcademic.AcademicCode + "' as KSCJ,";
                    mSqlExport = mSqlExport + "'" + mEOralAcademic.OralStatus.ToString() + "' as KYZK,";
                    mSqlExport = mSqlExport + "'" + mEOralAcademic.ToneStatus.ToString() + "' as YYYD";

System.Data.OleDb.OleDbCommand OLDBCommInsert = new System.Data.OleDb.OleDbCommand(mSqlExport, mOLDBConn);
                    mOLDBConn.Open();
                    OLDBCommInsert.ExecuteNonQuery();
                    OLDBCommInsert.Dispose();
                    mOLDBConn.Close();
                }
                #endregion 导出数据到DBF

#region 提供下载

System.IO.FileStream fs = new System.IO.FileStream(mFilePath + "//" + mTableName + ".DBF", System.IO.FileMode.Open, System.IO.FileAccess.Read);

byte[] b = new Byte[fs.Length];
                fs.Read(b, 0, b.Length);
                fs.Flush();
                fs.Close();

//System.IO.File.Delete(SavePdfPath); 
                Response.Clear();
                Response.ClearHeaders();
                Response.Clear();
                Response.ClearHeaders();
                Response.Buffer = false;
                Response.ContentType = "application/octet-stream";      //ContentType;
                Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(mFilePath + "//" + mTableName + ".DBF", System.Text.Encoding.UTF8));
                Response.AppendHeader("Content-Length", b.Length.ToString());
                fs.Close();
                fs.Close();
                if (b.Length > 0)
                {
                    Response.OutputStream.Write(b, 0, b.Length);
                }

Response.Flush();
                Response.End();

#endregion 提供下载

其它相关:
      
转自:http://www.cnblogs.com/jyshi/

导出DBF,并且提供下载 [转]的更多相关文章

  1. 导出DBF,并且提供下载 .

    原文:导出DBF,并且提供下载 . 导出DBF,并且提供下载 #region Declare string mFilePath = MapPath("../DataTmp/");  ...

  2. asp.net导出dbf报错“未在本地计算机上注册“VFPOLEDB”提供程序。”

    导出dbf文件报错,提示“未在本地计算机上注册“VFPOLEDB”提供程序.” 可以尝试一下方法: 方法一:下载VFPOLEDBSetup.msi 安装 如果方法一不行:继续方法二:下载vfp9.0 ...

  3. php导出csv数据在浏览器中输出提供下载或保存到文件的示例

    来源:http://www.jb51.net/article/49313.htm 1.在浏览器输出提供下载 /** * 导出数据到CSV文件 * @param array $data 数据 * @pa ...

  4. RDIFramework.NET平台代码生成器V3.0版本全新发布-更新于20160518(提供下载)

    最新版本请转到:RDIFramework.NET平台代码生成器V3.1版本全新发布-更新于2016-10-08(提供下载) RDIFramework.NET代码生成器V3.0版本修改了针对3.0版本的 ...

  5. Word 打包 zip 并提供下载

    该篇博客记录Java Web项目将word打包zip并提供下载功能的实现和其中遇到的坑,方便后续自己的查看的参照. 1. 后台处理的java 方法 首先将所有的word生成到uploadword目录下 ...

  6. RDIFramework.NET平台代码生成器V2.8发布-更新于2014-12-31(提供下载)

    RDIFramework.NET平台代码生成器V2.8发布  更新于2014-12-31 注:已经发布了新版本,请转新版本下载: RDIFramework.NET平台代码生成器V3.0版本全新发布-更 ...

  7. iOS开发UI篇—推荐两个好用的Xcode插件(提供下载链接)

    iOS开发UI篇—推荐两个好用的Xcode插件(提供下载链接) 这里推荐两款好用的Xcode插件,并提供下载链接. 一.插件和使用如下: 1.两款插件 对项目中图片提供自动提示功能的插件:KSImag ...

  8. RDIFramework.NET平台代码生成器V1.0发布(提供下载)

    RDIFramework.NET平台代码生成器V1.0发布(提供下载)   RDIFramework.NET(.NET快速开发整合框架)框架做为信息化系统快速开发.整合的框架,其目的一至是给用户和开发 ...

  9. 推荐两个好用的Xcode插件(提供下载链接)

    这里推荐两款好用的Xcode插件,并提供下载链接. 一.插件和使用如下: 1.两款插件 对项目中图片提供自动提示功能的插件:KSImageNamed-Xcode-master 提供快速创建自动注释:V ...

随机推荐

  1. lua userdata

    #define metatablename "studentlib.06-11-11" /** * utility functions */ static int pusherro ...

  2. java一行一行写入或读取数据

    原文:http://www.cnblogs.com/linjiqin/archive/2011/03/23/1992250.html 假如E:/phsftp/evdokey目录下有个evdokey_2 ...

  3. Mac安装GitLab CE记录

    0 REF REF1 原始的GitLab Documentation REF2 Installation-guide-for-GitLab-on-OS-X REF3 如何在Mac 终端升级ruby版本 ...

  4. iOS AppStore提交错误收集

    ERROR ITMS-90535: "Unexpected CFBundleExecutable Key. The bundle at 'Payload/创可贴.app/TencentOpe ...

  5. (转)Spring AOP实现方式(转)

    我们可以通过三种方式来使用Spring AOP,它们分别是:@Aspect-based(Annotation),Schema-based(XML),以及底层的Spring AOP API 底层的Spr ...

  6. 《Android深度探索HAL与驱动开发》第三章阅读心得

    Git是Linux内核代码对源代码进行管理的软件,他的各方面要优与其他同类的源代码管理软件. 安装Git后,查看Git文档在Linux下可以直接使用man命令看指令的帮助文档.安装git-doc后会安 ...

  7. 拓展Yii Framework(易框架)

    1.拓展yii 此文针对Yii1.1.15而写,请注意甄别你的Yii Framework 版本. 拓展yii是开发期间常见的代码处理方式.例如,你写一个新的controller(业务控制器),你通过继 ...

  8. Git分支管理

    一.Git分支的使用 查看分支: git branch 创建分支: git branch branch1 切换到branch1 git checkout branch1 再用git branch查看, ...

  9. Here's to the crazy ones.

    Here's to the crazy ones. The misfits. The rebels. The troublemakers. The round pegs in the square h ...

  10. Python + Selenium 实现登录Office 365

    最近捡起之前用的Python + Selenium实现工作中需要的登录Office 365功能.(吐槽:国内网络真是卡,登录Office 365实属不易.另外Selenium这样的网站都要墙,无法理解 ...