在 FROM 下創建主從報表的例子(代碼碎片)

来源:互联网 发布:淘宝男内裤买家秀图片 编辑:程序博客网 时间:2024/05/17 23:40
 
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Data; 

namespace Windowsbaobiao
{
    
/// <summary>
    
/// Form3 的摘要描述。
    
/// </summary>

    public class Form3 : System.Windows.Forms.Form
    
{
        
public CrystalReport1 oRpt=null;
        
private CrystalDecisions.Windows.Forms.CrystalReportViewer crystalReportViewer1;
        
/// <summary>
        
/// 設計工具所需的變數。
        
/// </summary>

        private System.ComponentModel.Container components = null;

        
public Form3()
        
{
            
//
            
// Windows Form 設計工具支援的必要項
            
//
            InitializeComponent();

            
//
            
// TODO: 在 InitializeComponent 呼叫之後加入任何建構函式程式碼
            
//
        }


        
/// <summary>
        
/// 清除任何使用中的資源。
        
/// </summary>

        protected override void Dispose( bool disposing )
        
{
            
if( disposing )
            
{
                
if(components != null)
                
{
                    components.Dispose();
                }

            }

            
base.Dispose( disposing );
        }


        
Windows Form 設計工具產生的程式碼

        
private void Form3_Load(object sender, System.EventArgs e)
        
{
            oRpt
=new CrystalReport1();
            Dataset1 ds
=new Dataset1();
            OleDbConnection oleConn
=new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:/Program Files/Microsoft Visual Studio .NET 2003/Crystal Reports/Samples/Database/cht/xtreme.mdb");
            OleDbDataAdapter oleAdapter 
=new OleDbDataAdapter ("select * from 訂購",oleConn);
            oleAdapter.Fill (ds,
"訂購");
            OleDbDataAdapter oleDetailsAdapter 
=new OleDbDataAdapter ("select * from 訂貨明細",oleConn);
            oleDetailsAdapter.Fill (ds,
"訂貨明細");
            oRpt.SetDataSource (ds);
            
this.crystalReportViewer1.ReportSource=oRpt; 
        }

    }

}

原创粉丝点击