从数据库导出数据 [英] exporting data from database

查看:61
本文介绍了从数据库导出数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从数据库导出批量数据,我的代码正在运行。但是数据只保存在服务器系统中。我需要在本地系统中保存批量数据,请帮助任何一个

  public   void  SaveWorkbook(){

String folderPath = C:\\My Files \\ + this .folder;
我的路径附在这里





我的代码附在这里。

我的路径( string  reportFileName =  @  C: \ Bondreg \ + l +  。pdf;)仅将时间数据导出到服务器系统。如果可能,在本地系统中保存数据

受保护 void Button2_Click( object sender,EventArgs e)
{
List l = new List();
sc.Open();
SqlCommand cmd = new SqlCommand( select来自BOND_REG的Fliono,其中status ='A',sc);
SqlDataReader SDR = cmd.ExecuteReader();


while (SDR.Read()== true
{
var item1 = SDR.GetValue( 0 )。ToString( );
l.Add(item1);
}
SDR.Close();
sc.Close();

for int i = 0 ; i < l.Count; i ++)
{
fileexport(l [i] .ToString()) ;
updatestaus(l [i] .ToString());

}

SDR.Close();
sc.Close();
Response.Write( < Script> alert('Data Exported Succesfully')< / Script> );
DropDownList1.SelectedIndex = 0 ;

}
public void updatestaus( string s)
{
sc.Open();
SqlCommand cmd = new SqlCommand( update BOND_REG设置状态='P',其中fliono =' + s.ToString()+ ' ,sc);
cmd.ExecuteNonQuery();
sc.Close();
}
public void fileexport( string l)
{

SqlCommand cmd1 = new SqlCommand( 从BOND_REG中选择*,其中status ='A'和Fliono =' + l + ',sc);

SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd1;
DataTable datatable = new DataTable();
da.Fill(datatable);
ReportDocument crystalReport = new ReportDocument();
crystalReport.Load(Server.MapPath( 〜/ bond.rpt));
crystalReport.SetDataSource(datatable);
ExportOptions rptExportOption;
DiskFileDestinationOptions rptFileDestOption = new DiskFileDestinationOptions();
PdfRtfWordFormatOptions rptFormatOption = new PdfRtfWordFormatOptions();
string reportFileName = @ C:\\ \\ Bondreg \ + l + 。pdf;
rptFileDestOption.DiskFileName = reportFileName;
rptExportOption = crystalReport.ExportOptions;
{
rptExportOption.ExportDestinationType = ExportDestinationType.DiskFile;
rptExportOption.ExportFormatType = ExportFormatType.PortableDocFormat;
rptExportOption.ExportDestinationOptions = rptFileDestOption;
rptExportOption.ExportFormatOptions = rptFormatOption;
}

crystalReport.Export();
crystalReport.Close();
crystalReport.Dispose();

解决方案

我在这里做了一个很大的假设,你正在执行SELECT数据库命令并希望保存包含数据的文件。



试试这个例子:

http://www.aspsnippets.com/Articles/Export-数据从SQL-Server到CSV-file-in-ASPNet-using-C-and-VBNet.aspx [ ^ ]



如果此示例不适合您的问题,请描述您的方案特定的更多细节。



也试试这个

这个例子更适合PDF文件保存。

http://stackoverflow.com/questions/5586772/asp-net-sending-a-pdf-to-在使用

I need to export bulk data from database,my code is working.but data saved in server system only .i need to save bulkdata in local system also,pls help any one

public void SaveWorkbook(){

    String folderPath = C:\\My Files\\+ this.folder ;
My path attached here



My code attached here.

My path(string reportFileName = @"C:\Bondreg\" + l + ".pdf";) while exporting time data saving to server system only . If possible to save data in local system .

protected void Button2_Click(object sender, EventArgs e)
{
List l = new List();
sc.Open();
SqlCommand cmd = new SqlCommand("select Fliono from BOND_REG where status='A'", sc);
SqlDataReader SDR = cmd.ExecuteReader();


while (SDR.Read() == true)
{
var item1 = SDR.GetValue(0).ToString();
l.Add(item1);
}
SDR.Close();
sc.Close();

for (int i = 0; i < l.Count; i++)
{
fileexport(l[i].ToString());
updatestaus(l[i].ToString());

}

SDR.Close();
sc.Close();
Response.Write("<Script> alert('Data Exported Succesfully')</Script>");
DropDownList1.SelectedIndex = 0;

}
public void updatestaus(string s)
{
sc.Open();
SqlCommand cmd = new SqlCommand("update BOND_REG set status='P' where fliono ='" + s.ToString() + "'", sc);
cmd.ExecuteNonQuery();
sc.Close();
}
public void fileexport(string l)
{

SqlCommand cmd1 = new SqlCommand("select * from BOND_REG where status='A' and Fliono ='" + l + "'", sc);

SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd1;
DataTable datatable = new DataTable();
da.Fill(datatable);
ReportDocument crystalReport = new ReportDocument();
crystalReport.Load(Server.MapPath("~/bond.rpt"));
crystalReport.SetDataSource(datatable);
ExportOptions rptExportOption;
DiskFileDestinationOptions rptFileDestOption = new DiskFileDestinationOptions();
PdfRtfWordFormatOptions rptFormatOption = new PdfRtfWordFormatOptions();
string reportFileName = @"C:\Bondreg\" + l + ".pdf";
rptFileDestOption.DiskFileName = reportFileName;
rptExportOption = crystalReport.ExportOptions;
{
rptExportOption.ExportDestinationType = ExportDestinationType.DiskFile;
rptExportOption.ExportFormatType = ExportFormatType.PortableDocFormat;
rptExportOption.ExportDestinationOptions = rptFileDestOption;
rptExportOption.ExportFormatOptions = rptFormatOption;
}

crystalReport.Export();
crystalReport.Close();
crystalReport.Dispose();

解决方案

AsI'm making a big assumption here that you are performing a SELECT database command and wanting to save a file containing the data.

Try this example:
http://www.aspsnippets.com/Articles/Export-data-from-SQL-Server-to-CSV-file-in-ASPNet-using-C-and-VBNet.aspx[^]

If this example does not suit your problem, please describe more detail specific to your scenario.

Also try this
This example is more suited to PDF file saving.
http://stackoverflow.com/questions/5586772/asp-net-sending-a-pdf-to-the-use


这篇关于从数据库导出数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆