乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      在VS2010Winform項(xiàng)目中使用RDLC報(bào)表定義文件、ReportViewer控件生...

       伊本經(jīng)閣 2012-04-11

      在VS2010Winform項(xiàng)目中使用RDLC報(bào)表定義文件、ReportViewer控件生成本地報(bào)表

      這是一個(gè)使用RDLC報(bào)表定義文件、ReportViewer控件生成本地報(bào)表的簡(jiǎn)單示例。(此文章存在瑕疵,2011.10.29重新編輯)
      一、新建一個(gè).net4.0項(xiàng)目:(下圖的.NET Framework 2.0 改為 .NET Framework 4.0----2011.10.29)
      該項(xiàng)目命名為ReportApp,為項(xiàng)目新建兩個(gè)文件夾 Reports、Datasets。Reports文件夾存儲(chǔ)報(bào)表定義文件,Datasets存儲(chǔ)數(shù)據(jù)集。
      二、創(chuàng)建Dataset
      1、第一個(gè)Dataset:確保解決方案資源管理器中選中Datasets后,點(diǎn)擊 菜單中的“項(xiàng)目”;“添加新項(xiàng)”;選擇左側(cè) “數(shù)據(jù)”,再選擇“數(shù)據(jù)集”;命名為FirstDataSet.xsd,如下圖.
      在“服務(wù)器資源管理器”中新建一個(gè)到Northwind.mdb數(shù)據(jù)庫(kù)的連接,并將Northwind.mdb數(shù)據(jù)庫(kù)添加到項(xiàng)目中。
      將Northwind.mdb中的Products表拖至FirstDataset.xsd中。
      2、同樣的方法創(chuàng)建第二個(gè)Dataset:SecondDataset.xsd。將將Northwind.mdb中的Orders表拖至其中。
      三、創(chuàng)建Reports
      1、第一個(gè)報(bào)表ReportProducts:確保解決方案資源管理器中選中Reports后,點(diǎn)擊 菜單中的“項(xiàng)目”;“添加新項(xiàng)”;選擇左側(cè) “Reporting”,再選擇“報(bào)表”;命名為ReportProducts.rdlc,如下圖。
      修改ReportProducts.rdlc文件屬性中的“復(fù)制到輸出目錄”,改為:始終復(fù)制。如果不修改此屬性,下面生成報(bào)表時(shí)將找不到報(bào)表定義文件。
      選擇左側(cè)的“報(bào)表數(shù)據(jù)”工具箱,新建一個(gè)數(shù)據(jù)集。
      命名數(shù)據(jù)集名稱為:RpProductsDataset,此名稱在后面的Code有用。選擇數(shù)據(jù)源為FirstDataset,選擇可用數(shù)據(jù)集為Products。
      在工具箱里拖拽一個(gè)表至報(bào)表,將Tablix1的datasetname設(shè)為RpProductsDataSet,然后設(shè)置表格各個(gè)單元的字段。
      2、使用同樣的方法建立第二個(gè)報(bào)表:ReportOrders.rdlc,報(bào)表的數(shù)據(jù)集名稱為RpOrdersDataset。
      四、生成報(bào)表
      雙擊打開form1.vb,從工具箱中將ReportViewer控件拖至Form1中。如果在VS2010 中找不到ReportViewer控件,可以右擊工具箱中的“數(shù)據(jù)”,選擇"選擇項(xiàng)...",從中選擇ReportViewer控件。注意:有winform版和web版共兩種ReportViewer控件。
      將ReportViewer控件的Anchor屬性設(shè)置為Top, Bottom, Left, Right。form1的WindowState屬性設(shè)置為Maximized。
      從工具箱中拖拽兩個(gè)Button,分別命名為ReportProducts、ReportOrders。
      form1的代碼如下:
       
      Public Class Form1
        
          'Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        
          '    Me.ReportViewer1.RefreshReport()
          'End Sub
        
          'ReportProducts報(bào)表
          Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
              '定義數(shù)據(jù)集
              Dim ProductsDS As New FirstDataSet
              '數(shù)據(jù)SQL命令
              Dim commandtext As String = "select * from Products"
              '報(bào)表定義文件
              Dim rdlcfile As String = "Reports/ReportProducts.rdlc"
              '報(bào)表中使用的數(shù)據(jù)集名稱
              Dim reportds As String = "RpProductsDataSet"
              '生成報(bào)表
              Me.GetReport(ProductsDS, commandtext, rdlcfile, reportds, False)
        
          End Sub
        
          'ReportOrders報(bào)表
          Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
              '定義數(shù)據(jù)集
              Dim ProductsDS As New SecondDataSet
              '數(shù)據(jù)SQL命令
              Dim commandtext As String = "select * from orders"
              '報(bào)表定義文件
              Dim rdlcfile As String = "Reports/ReportOrders.rdlc"
              '報(bào)表中使用的數(shù)據(jù)集名稱,注意:名稱中大小寫敏感
              Dim reportds As String = "rpOrdersDataset"
              '生成報(bào)表
              Me.GetReport(ProductsDS, commandtext, rdlcfile, reportds, True)
          End Sub
        
          Private Sub GetReport(ByVal ds As DataSet, ByVal Commandtext As String, ByVal RDLCFile As String, ByVal ReportDS As String, ByVal isLandscape As Boolean)
              'ds:使用哪一個(gè)數(shù)據(jù)集
              'Commandtext:數(shù)據(jù)SQL命令
              'RDLCFile:RDLC文件路徑及文件名
              'ReportDS:RDLC報(bào)表文件使用的數(shù)據(jù)集名稱
              'isLandscape:報(bào)表頁(yè)面是否以橫向顯示
        
              '----------------------------獲取數(shù)據(jù)----------------------------------
              '定義數(shù)據(jù)集
              'Dim DataSetUsed As New ds
              '定義連接
              Dim conn As New OleDb.OleDbConnection
              '連接的關(guān)鍵字從配置中獲取
              conn.ConnectionString = My.Settings.NorthwindConnectionString
              '定義數(shù)據(jù)命令
              Dim comm As New Data.OleDb.OleDbCommand
              comm.CommandType = CommandType.Text
              comm.CommandText = Commandtext
              comm.Connection = conn
              '定義數(shù)據(jù)適配器
              Dim DA As New OleDb.OleDbDataAdapter(comm)
              '填充數(shù)據(jù)
              Using conn
                  conn.Open()
                  DA.Fill(ds.Tables(0))
              End Using
        
              '--------------------------------生成報(bào)表-----------------------------
              '設(shè)置使用本地報(bào)表模式
              Me.ReportViewer1.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Local
              '清空ReportViewer1控件原有的數(shù)據(jù)源
              Me.ReportViewer1.LocalReport.DataSources.Clear()
              '定義本地報(bào)表變量
              Dim ReportEngine As Microsoft.Reporting.WinForms.LocalReport
              ReportEngine = ReportViewer1.LocalReport
              '指定報(bào)表文件
              ReportEngine.ReportPath = RDLCFile
              '加載數(shù)據(jù)源,注意:數(shù)據(jù)集的大小寫是敏感的。
              ReportEngine.DataSources.Add(New Microsoft.Reporting.WinForms.ReportDataSource(ReportDS, ds.Tables(0)))
        
              '---------------------設(shè)置預(yù)覽---------------------------------
        
              '顯示模式是打印預(yù)覽模式
              Me.ReportViewer1.SetDisplayMode(Microsoft.Reporting.WinForms.DisplayMode.PrintLayout)
              '頁(yè)面設(shè)置變量
              Dim pageset As Drawing.Printing.PageSettings = Me.ReportViewer1.GetPageSettings
              '頁(yè)面是否是橫向顯示
              pageset.Landscape = isLandscape
              '設(shè)置頁(yè)面
              Me.ReportViewer1.SetPageSettings(pageset)
              '以百分比顯示
              Me.ReportViewer1.ZoomMode = Microsoft.Reporting.WinForms.ZoomMode.Percent
              '100%的比例
              Me.ReportViewer1.ZoomPercent = 100
        
              '刷新報(bào)表
              Me.ReportViewer1.RefreshReport()
          End Sub
      End Class
      最后的效果如下:<BR>  
       
      后記:關(guān)于RDLC報(bào)表的部署
           reportviewer控件不屬于.net framework 框架的一部分。如果要發(fā)布報(bào)表,需要安裝Microsoft Report Viewer 2010 Redistributable Package  (下載地址:http://www.microsoft.com/downloads/zh-cn/details.aspx?familyid=A941C6B2-64DD-4D03-9CA7-4017A0D164FD&displaylang=zh-cn),用于查看使用 Microsoft 報(bào)表技術(shù)設(shè)計(jì)的報(bào)表的控件。發(fā)布應(yīng)用程序時(shí),項(xiàng)目->屬性->發(fā)布->系統(tǒng)必備  勾選Microsoft Visual Studio 2010報(bào)表查看器   。      
       

        本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評(píng)論

        發(fā)表

        請(qǐng)遵守用戶 評(píng)論公約

        類似文章 更多