Export DBF, and provide download [go]

Source: Internet
Author: User

Export DBF, and provide download

#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 Creating a dbf Table file

#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 Creating a dbf Table file

#region Export Data to 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 Export Data to DBF

Download Available #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 ();

Download available #endregion

Other Related:
transferred from:http://www.cnblogs.com/jyshi/

Export DBF, and provide download [go]

Related Article

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.