熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

VS2010 水晶報表的使用方法

2022-06-13   來源: .NET編程 

  在VS中新建一個“Windows 窗體應用程序”項目在該項目中添加一個水晶報表“CrystalReportrpt”然後在項目上點擊鼠標右鍵屬性將“目標框架”改為“Net Framework

2013-06-20_003334
 

  打開appconfig文件在“startup”節點一個“useLegacyVRuntimeActivationPolicy="true"”屬性

復制代碼 代碼如下:
<startup useLegacyVRuntimeActivationPolicy="true">
<supportedRuntime version="v" sku="NETFrameworkVersion=v"/>
</startup>

  在Form窗體中從工具箱拖出一個Crystal Report Viewer控件雙擊Form窗體是雙擊Form窗體不是Crystal Report Viewer在後台的Form_Load事件中寫入如下代碼

復制代碼 代碼如下:
private void Form_Load(object sender EventArgs e)
{
string connStr = "Data Source=SqlExpress;Initial Catalog=dbTest;User ID=sa;Password=test";
SqlConnection conn = new SqlConnection(connStr);
connOpen();
try
{
string sql = "SELECT * FROM Customer where email!=test@gmailcom";
SqlDataAdapter sda = new SqlDataAdapter(sql conn);
DataSet ds = new DataSet();
sdaFill(ds "tmpTable");

  string reportPath = SystemWindowsFormsApplicationStartupPath + @"CrystalReportrpt";
ReportDocument rd = new ReportDocument();
rdLoad(reportPath);
rdSetDataSource(dsTables[]DefaultView);
thiscrystalReportViewerReportSource = rd;
}
catch (Exception ex)
{
throw new Exception(exMessageToString());
}
finally
{
connClose();
}
}

  這樣就OK了
 

2013-06-19_234029

From:http://tw.wingwit.com/Article/program/net/201311/14223.html
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.