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

打開app.config文件,在“startup”節(jié)點(diǎn)一個“useLegacyV2RuntimeActivationPolicy="true"”屬性
復(fù)制代碼 代碼如下:<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
在Form1窗體中,從工具箱拖出一個Crystal Report Viewer控件,雙擊Form窗體,是雙擊Form窗體,不是Crystal Report Viewer,在后臺的Form_Load事件中寫入如下代碼:
復(fù)制代碼 代碼如下: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!='[email protected]'";
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頁面?zhèn)髦禍y試實(shí)例代碼WebForm_1.aspx內(nèi)容如下: 復(fù)制代碼 代碼如下: %@ Page Language=C# AutoEventWireup=true CodeBehind=WebForm_1.aspx.cs Inherits=頁面?zhèn)髦?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發(fā)送Email實(shí)例(可帶附件)
- js實(shí)現(xiàn)廣告漂浮效果的小例子
- asp.net Repeater 數(shù)據(jù)綁定的具體實(shí)現(xiàn)
- Asp.Net 無刷新文件上傳并顯示進(jìn)度條的實(shí)現(xiàn)方法及思路
- Asp.net獲取客戶端IP常見代碼存在的偽造IP問題探討
- ASP.NET中操作SQL數(shù)據(jù)庫(連接字符串的配置及獲取)
- asp.net頁面?zhèn)髦禍y試實(shí)例代碼
- DataGridView - DataGridViewCheckBoxCell的使用介紹
- asp.net中javascript的引用(直接引入和間接引入)
- 三層+存儲過程實(shí)現(xiàn)分頁示例代碼
- 模板無憂:在.NET開發(fā)中靈活使用TreeView控件
- 相關(guān)鏈接:
- 教程說明:
.Net教程-VS2010 水晶報表的使用方法
。