Bài 4 : Tạo reports từ Sql query

Bài 4 : Tạo reports từ Sql query

Ở bài này tui sẽ tạo report từ kết quả của các query trong Sql, vẫn sử dụng DataSet. Tui sẽ tạo report cho bảng Product trong cái database đã nói ở bài trên cùng nhé,câu truy vấn của chúng ta như sau :

sql = "SELECT Product_id,Product_name,Product_price FROM Product";

Tạo mới 1 project winform và add vào 1 DataSet mới,trên DataSet đó tạo thêm 1 DataTable, và trên DataTable đó ta add 3 column vào nhá

Bài 4 : Tạo reports từ Sql query

Tuơng tự như bài vừa trên, tui sẽ tạo thêm 1 crytal report và vẫn sử dụng ProjectData :

Ở bước kế tiếp tui sẽ chọn cả 3 fields Product_id,Product_name,Product_price.

Đã xong phần thiết kế report. Theo truyền thống, ta lai tạo 1 button và 1 crytalReportViewer như mấy cái trên kia nhé

private void button1_Click(object sender, EventArgs e)
        {
            SqlConnection cnn;
            string connectionString = null;
            string sql = null;

            connectionString = "server=.\\sqlexpress;database=example;integrated security=true";
            cnn = new SqlConnection(connectionString);
            cnn.Open();
            sql = "SELECT Product_id,Product_name,Product_price FROM Product";
            SqlDataAdapter dscmd = new SqlDataAdapter(sql, cnn);
            DataSet1 ds = new DataSet1();
            dscmd.Fill(ds, "Product");
            MessageBox.Show(ds.Tables[1].Rows.Count.ToString());
            cnn.Close();

            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.5 (2 votes)
Ả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

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

 
Mark Zuckerberg

CEO Facebook – MARK ZUCKERBERG, thành công bằng cách nào

Nếu bạn có sử dụng Facebook thường xuyên để kết nối và cập nhật thông tin của bạn bè thì chắc chắn bạn không thể không biết đến Mark Zuckerberg

Xóa Duplicate Views Results trong Drupal 7

Xóa Duplicate Views Results trong Drupal 7

When you are building a Drupal site and creating views, it's not uncommon to find that your view is showing the same result multiple times.

Tạo chiến dịch email cho hoạt động bán hàng trên Drupal Commerce

Tạo chiến dịch email cho hoạt động bán hàng trên Drupal Commerce

Having the ability to send a targeted email to all purchasers of ‘product X’ can be priceless.

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

 

Diet con trung