VS2010 水晶報表的使用方法_.Net教程
推薦:ASP.NET中操作SQL數據庫(連接字符串的配置及獲取)在WebConfig中配置數據庫連接字符串,代碼如下: 復制代碼 代碼如下: connectionStrings add name=ConnectionString connectionString=user id=用戶名;password=密碼;initial catalog=數據庫名稱;data source=服務器名稱/ /connectionStrings 然后在Webform_1.aspx.cs
在VS2010中新建一個“Windows 窗體應用程序”項目,在該項目中添加一個水晶報表“CrystalReport1.rpt”,然后在項目上點擊鼠標右鍵屬性,將“目標框架”改為“.Net Framework 4”

打開app.config文件,在“startup”節點一個“useLegacyV2RuntimeActivationPolicy="true"”屬性
復制代碼 代碼如下:<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
在Form1窗體中,從工具箱拖出一個Crystal Report Viewer控件,雙擊Form窗體,是雙擊Form窗體,不是Crystal Report Viewer,在后臺的Form_Load事件中寫入如下代碼:
復制代碼 代碼如下:private void Form1_Load(object sender, EventArgs e)
{
string connStr = "Data Source=.\SqlExpress;Initial Catalog=dbTest;User ID=sa;Password=test";
SqlConnection conn = new SqlConnection(connStr);
conn.Open();
try
{
string sql = "SELECT * FROM Customer where email!='test@gmail.com'";
SqlDataAdapter sda = new SqlDataAdapter(sql, conn);
DataSet ds = new DataSet();
sda.Fill(ds, "tmpTable");
string reportPath = System.Windows.Forms.Application.StartupPath + @"CrystalReport1.rpt";
ReportDocument rd = new ReportDocument();
rd.Load(reportPath);
rd.SetDataSource(ds.Tables[0].DefaultView);
this.crystalReportViewer1.ReportSource = rd;
}
catch (Exception ex)
{
throw new Exception(ex.Message.ToString());
}
finally
{
conn.Close();
}
}
這樣就OK了

分享:asp.net頁面傳值測試實例代碼WebForm_1.aspx內容如下: 復制代碼 代碼如下: %@ Page Language=C# AutoEventWireup=true CodeBehind=WebForm_1.aspx.cs Inherits=頁面傳值.WebForm_1 % !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transit
- asp.net如何得到GRIDVIEW中某行某列值的方法
- .net SMTP發送Email實例(可帶附件)
- js實現廣告漂浮效果的小例子
- asp.net Repeater 數據綁定的具體實現
- Asp.Net 無刷新文件上傳并顯示進度條的實現方法及思路
- Asp.net獲取客戶端IP常見代碼存在的偽造IP問題探討
- ASP.NET中操作SQL數據庫(連接字符串的配置及獲取)
- asp.net頁面傳值測試實例代碼
- DataGridView - DataGridViewCheckBoxCell的使用介紹
- asp.net中javascript的引用(直接引入和間接引入)
- 三層+存儲過程實現分頁示例代碼
- 模板無憂:在.NET開發中靈活使用TreeView控件
- 相關鏈接:
- 教程說明:
.Net教程-VS2010 水晶報表的使用方法
。