• 大小: 198KB
    文件类型: .rar
    金币: 2
    下载: 1 次
    发布日期: 2021-06-11
  • 语言: C#
  • 标签: winform  reportViewer  

资源简介

利用reportViewer控件设计打印模板,实现数据库指定记录的打印

资源截图

代码片段和文件信息

using Microsoft.Reporting.WinForms;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace PrinterDemo
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender EventArgs e)
        {
            // TODO:  这行代码将数据加载到表“sysDataSet1.sell”中。您可以根据需要移动或删除它。
            this.sellTableAdapter.Fill(this.sysDataSet1.sell);
            
            this.reportViewer1.RefreshReport();
        }

        private void reportViewer1_Load(object sender EventArgs e)
        {
            reportViewer1.Clear();
            int id=1;
            string connstring = “Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\\sys.accdb“;

            OleDbConnection conn = new OleDbConnection(connstring);

            OleDbCommand cmd = conn.CreateCommand();
            cmd.CommandText = “select * from sell where id =@id“;
            cmd.Parameters.Add(new OleDbParameter(“@id“ id));

            conn.Open();
            cmd.ExecuteNonQuery();

            DataTable dt = new DataTable();

            try
            {
                OleDbDataAdapter ada1 = new OleDbDataAdapter(cmd);
                ada1.Fill(dt);

            }
            finally
            {
                conn.Close();
                cmd.Dispose();
                conn.Dispose();
            }
            ReportDataSource rds = new ReportDataSource(“DataSet1“ dt);
            this.reportViewer1.LocalReport.DataSources.Clear();

            this.reportViewer1.LocalReport.DataSources.Add(rds);
            //为报表浏览器指定报表文件
            this.reportViewer1.LocalReport.ReportembeddedResource = “RepairBill.UI.RepairReport.rdlc“;  //指定数据集数据集名称后为表不是DataSet类型的数据集  

            this.reportViewer1.RefreshReport();
            //reportViewer1.clear();
            //this.reportViewer2.RefreshReport();

        }
    }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件        788  2017-10-02 11:13  PrinterDemo\PrinterDemo\App.config

     文件     417792  2017-10-02 11:22  PrinterDemo\PrinterDemo\bin\Debug\db\sys.accdb

     文件      81920  2018-05-30 14:03  PrinterDemo\PrinterDemo\bin\Debug\PrinterDemo.exe

     文件        788  2017-10-02 11:13  PrinterDemo\PrinterDemo\bin\Debug\PrinterDemo.exe.config

     文件     110080  2018-05-30 14:03  PrinterDemo\PrinterDemo\bin\Debug\PrinterDemo.pdb

     文件      23168  2018-05-30 14:06  PrinterDemo\PrinterDemo\bin\Debug\PrinterDemo.vshost.exe

     文件        788  2017-10-02 11:13  PrinterDemo\PrinterDemo\bin\Debug\PrinterDemo.vshost.exe.config

     文件     417792  2017-10-02 11:24  PrinterDemo\PrinterDemo\bin\Debug\sys.accdb

     文件       2305  2017-10-02 11:46  PrinterDemo\PrinterDemo\Form1.cs

     文件       4718  2017-10-02 11:59  PrinterDemo\PrinterDemo\Form1.Designer.cs

     文件       7459  2017-10-02 11:46  PrinterDemo\PrinterDemo\Form1.resx

     文件      20902  2018-02-09 08:39  PrinterDemo\PrinterDemo\obj\Debug\DesignTimeResolveAssemblyReferences.cache

     文件       7736  2018-05-30 14:03  PrinterDemo\PrinterDemo\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件       1732  2018-05-30 14:06  PrinterDemo\PrinterDemo\obj\Debug\PrinterDemo.csproj.FileListAbsolute.txt

     文件       1035  2018-05-30 14:02  PrinterDemo\PrinterDemo\obj\Debug\PrinterDemo.csproj.GenerateResource.Cache

     文件      34938  2018-01-31 09:03  PrinterDemo\PrinterDemo\obj\Debug\PrinterDemo.csprojResolveAssemblyReference.cache

     文件      81920  2018-05-30 14:03  PrinterDemo\PrinterDemo\obj\Debug\PrinterDemo.exe

     文件        180  2018-05-30 14:03  PrinterDemo\PrinterDemo\obj\Debug\PrinterDemo.Form1.resources

     文件     110080  2018-05-30 14:03  PrinterDemo\PrinterDemo\obj\Debug\PrinterDemo.pdb

     文件        180  2018-05-30 14:03  PrinterDemo\PrinterDemo\obj\Debug\PrinterDemo.Properties.Resources.resources

     文件        382  2017-10-02 11:46  PrinterDemo\PrinterDemo\obj\Debug\RdlCompile.cache

     文件          0  2017-10-02 11:46  PrinterDemo\PrinterDemo\obj\Debug\RdlCompile.compiled

     文件          0  2017-10-02 10:01  PrinterDemo\PrinterDemo\obj\Debug\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs

     文件          0  2017-10-02 10:01  PrinterDemo\PrinterDemo\obj\Debug\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs

     文件          0  2017-10-02 10:01  PrinterDemo\PrinterDemo\obj\Debug\TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs

     文件       9728  2017-10-02 11:13  PrinterDemo\PrinterDemo\obj\Debug\TempPE\sysDataSet.Designer.cs.dll

     文件      41984  2018-02-09 09:03  PrinterDemo\PrinterDemo\obj\Debug\TempPE\sysDataSet1.Designer.cs.dll

     文件       6878  2018-05-30 14:03  PrinterDemo\PrinterDemo\PrinterDemo.csproj

     文件        453  2017-10-02 10:37  PrinterDemo\PrinterDemo\PrinterDemo.csproj.user

     文件        523  2017-10-02 10:01  PrinterDemo\PrinterDemo\Program.cs

............此处省略31个文件信息

评论

共有 条评论