导出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. CS0016: 未能写入输出文件“c:\WINDOWS\Microsoft.NET\Framework\.。。”--“拒绝访问

    aspx 常见错误 CS0016: 未能写入输出文件“c:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/Temporary ASP.NET Files/... ...

  2. 创建html模板

    打开写好的html 复制  在页面上右击------属性  --会出现下面情况

  3. Hadoop YARN 100-1知识点

    0 YARN中实体 资源管理者(resource manager, RM) 长时间运行的守护进程,负责管理集群上资源的使用 节点管理者(node manager, NM) 长时间运行的守护进程,在集群 ...

  4. HDU 3342 Legal or Not(判断是否存在环)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3342 Legal or Not Time Limit: 2000/1000 MS (Java/Othe ...

  5. CCI4.4/LintCode Balanced Binary Tree, Binary Tree, Binary Search Tree

    Binary Tree: 0到2个子节点; Binary Search Tree: 所有左边的子节点 < node自身 < 所有右边的子节点: 1. Full类型: 除最下面一层外, 每一 ...

  6. 2015.10.18 do while练习

    /*乘法表*/ #define COLMAX 10 #define ROWMAX 12 main() { int row,column,y; row=1; printf("          ...

  7. 微软雅黑 在css里怎么写

    1.首先要了解css中是如何控制字体的. font:在一个声明中设置所有字体属性: font有以下几个属性: font-style:字体样式 font-variant:字体异体 font-weight ...

  8. SPARK SQL 中registerTempTable与saveAsTable的区别

    使用registerTempTable注册表是一个临时表,生命周期只在所定义的sqlContext或hiveContext实例之中.换而言之,在一个sqlontext(或hiveContext)中re ...

  9. Roslyn 学习笔记(二)

    参考:https://github.com/dotnet/roslyn/wiki/Getting-Started-C%23-Syntax-Analysis 语法分析过程主要用到以下类或结构: Synt ...

  10. get_headers()函数

    get_headers() 是PHP系统级函数,他返回一个包含有服务器响应一个 HTTP 请求所发送的标头的数组.如果失败则返回 FALSE 并发出一条 E_WARNING 级别的错误信息(可用来判断 ...