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

打開(kāi)app.config文件,在“startup”節(jié)點(diǎn)一個(gè)“useLegacyV2RuntimeActivationPolicy="true"”屬性
復(fù)制代碼 代碼如下:<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
在Form1窗體中,從工具箱拖出一個(gè)Crystal Report Viewer控件,雙擊Form窗體,是雙擊Form窗體,不是Crystal Report Viewer,在后臺(tái)的Form_Load事件中寫(xiě)入如下代碼:
復(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頁(yè)面?zhèn)髦禍y(cè)試實(shí)例代碼WebForm_1.aspx內(nèi)容如下: 復(fù)制代碼 代碼如下: %@ Page Language=C# AutoEventWireup=true CodeBehind=WebForm_1.aspx.cs Inherits=頁(yè)面?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 無(wú)刷新文件上傳并顯示進(jìn)度條的實(shí)現(xiàn)方法及思路
- Asp.net獲取客戶端IP常見(jiàn)代碼存在的偽造IP問(wèn)題探討
- ASP.NET中操作SQL數(shù)據(jù)庫(kù)(連接字符串的配置及獲取)
- asp.net頁(yè)面?zhèn)髦禍y(cè)試實(shí)例代碼
- DataGridView - DataGridViewCheckBoxCell的使用介紹
- asp.net中javascript的引用(直接引入和間接引入)
- 三層+存儲(chǔ)過(guò)程實(shí)現(xiàn)分頁(yè)示例代碼
- 模板無(wú)憂:在.NET開(kāi)發(fā)中靈活使用TreeView控件
.Net教程Rss訂閱編程教程搜索
.Net教程推薦
- C#中調(diào)用Windows API時(shí)的數(shù)據(jù)類型對(duì)應(yīng)關(guān)系
- ASP.NET 2.0中CSS不正常的解決方法
- 解決Asp.net MVC中頁(yè)面標(biāo)題的方法
- asp.net如何連接sql server2000數(shù)據(jù)庫(kù)
- 對(duì)C#中正則表達(dá)式的一些解讀和總結(jié)
- ASP.NET立即上手教程(10)
- 菜鳥(niǎo)也學(xué)習(xí)ASP.NET如何讀取數(shù)據(jù)庫(kù)內(nèi)容
- VS2010 水晶報(bào)表的使用方法
- 淺談ASP.NET兩個(gè)截取字符串的實(shí)用方法技巧
- 在ASP.NET中進(jìn)行文件處理(1)
- 相關(guān)鏈接:
- 教程說(shuō)明:
.Net教程-VS2010 水晶報(bào)表的使用方法
。