Bài 3: Tạo reports từ DataSet

Bài 3: Tạo reports từ DataSet

Mấy bài trước tui chỉ tạo report từ database, ở bài này tui sẽ tạo 1 report từ DataSet coi sao nhé. Tạo 1 project winform mới, add thêm vào 1 DataSet,giữ nguyên các thông tin mặc định của nó,trên DataSet đó ta tạo ra 1 datatable có 2 column là ID và Item

Bài 3: Tạo reports từ DataSet

Bây giờ ta sẽ tạo 1 report từ DataSet mới tạo ra. Vào menu Project->Add new item, chọn crytal report như mấy cái trên kia, để các thông số mặc định luôn cho tiện. Nhưng ở đây ta ko tạo ra connect tới database nào mà chọn luôn dataset lúc này :

Ở bước kế tiếp, chọn luôn cả 2 column của DataTable trên DataSet lúc nãy nhé

Bây giờ tạo thêm vào form 1 cái button và 1 crystalReportViewer control như mấy cái trước. Tui sẽ tạo dữ liệu đơn giản cho dataset và hiển thị ở report :

private void button1_Click(object sender, EventArgs e)
        {
            DataSet1 ds = new DataSet1();
            DataTable t = ds.Tables.Add("Items");
            t.Columns.Add("id", Type.GetType("System.Int32"));
            t.Columns.Add("Item", Type.GetType("System.String"));

            DataRow r;
            int i = 0;
            for (i = 0; i <= 9; i++)
            {
                r = t.NewRow();
                r["id"] = i;
                r["Item"] = "Item" + i;
                t.Rows.Add(r);
            }

            CrystalReport1 objRpt = new CrystalReport1();
            objRpt.SetDataSource(ds.Tables[1]);
            crystalReportViewer1.ReportSource = objRpt;
            crystalReportViewer1.Refresh();

        }

 

Bạn thấy bài viết này như thế nào?: 
Average: 9 (1 vote)
Ảnh của Tommy Tran

Tommy owner Express Magazine

Drupal Developer having 9+ year experience, implementation and having strong knowledge of technical specifications, workflow development. Ability to perform effectively and efficiently in team and individually. Always enthusiastic and interseted to study new technologies

  • Skype ID: tthanhthuy

Bình luận (0)

 

Add Comment

Filtered HTML

  • Các địa chỉ web và email sẽ tự động được chuyển sang dạng liên kết.
  • Các thẻ HTML được chấp nhận: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Tự động ngắt dòng và đoạn văn.

Plain text

  • No HTML tags allowed.
  • Các địa chỉ web và email sẽ tự động được chuyển sang dạng liên kết.
  • Tự động ngắt dòng và đoạn văn.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.

Advertisement

 

jobsora

Dich vu khu trung tphcm

Dich vu diet chuot tphcm

Dich vu diet con trung

Quảng Cáo Bài Viết

 
Những điều lưu ý khi thực hiện chiến dịch seo

Những điều lưu ý khi thực hiện chiến dịch seo

Ngày nay thương mại điện tử ngày càng phát triển hàng ngàn website ra đời, cũng đồng nghĩa với sự xuất hiện của nhiều công ty cung cấp dịch vụ seo ra đời và họ thường cố gắng..

Cách để Custom View Modes ở Individual Nodes dùng Display Suite

Cách để Custom View Modes ở Individual Nodes dùng Display Suite

When it comes to managing the look and feel of a content page, nothing can beat Display Suite. It's become an essential module for when you need to change the layout and fields on a node or any entity page.

Teens Exploring Technology tạo sự khác biệt gì tại South Los Angeles?

Teens Exploring Technology tạo sự khác biệt gì tại South Los Angeles?

Oscar was looking into Drupal as a potential technology to include in the summer coding academy his organization holds every year.

Công ty diệt chuột T&C

 

Diet con trung