C# - Hướng dẫn tạo Crystal Reports bằng Dataset

C# - Hướng dẫn tạo Crystal Reports bằng Dataset

>>Hướng dẫn tạo Crystal Reports trong C# (Phần 2)

>>Hướng dẫn sử dụng Crystal Reports (Phần 1)

C# - Hướng dẫn tạo Crystal Reports bằng Dataset

Giới thiệu

Hiện tại có rất ít bài tiếng việt hướng dẫn về phần này.
" creating Crystal Reports using C#.NET" .
Tạo một Crystal Reports trong C#.Net với CSDL access
SQL sercer làm tương tự.

Tạo dataset

Đầu tiên bạn tạo 1 dự án Sau đó

“Add New Item” trong “Project” menu, bạn add a Dataset  Giống hình bên dưới.

String connString = @"Provider=Microsoft.Jet.OLEDB.4.0;_
    Data Source=..\\..\\myDB.mdb;User ID=Admin;Password=";

OleDbConnection conn = new OleDbConnection(connString);
conn.Open();
string query = "SELECT studentID, firstName, lastName, birthDate, _
                address, contactNo FROM studentInfo";
OleDbDataAdapter oleDA = new OleDbDataAdapter(query,conn);

Tạo một báo cáo dùng Crystal Reports

Sau khi tao xong dataset bạn add a Crystal Report vào project bằng cách “Add New Item” trong “Project” menu. Sau đó chọn tên xuất hiện rồi nhấn nút ok.

Màn hình sẽ hiển thị như sau bạn chọn mặt định rồi ấn OK
Sau đó chọn table rùi insert table phần này có thể khác so với VB2005 nhưng cũng tương tự thôi!

sau đó chọn các fields hiển thị trong report --> nhần nút add

Xong xu bạn nhấn nút next-->cuối cùng chọn style kiểu bạn muốn report hiển thị

Kế tiếp bạn sẽ cho report hiển thị trên form

Bạn tao một form và add crystalReportViewer viết code trong thuộc tính page load

// code to get data from the DB
DBConnection DBConn = new DBConnection();
OleDbDataAdapter myDataAdapter = DBConn.getDataFromDB();

// use the created Dataset to fill it with data got
// from the DB by using the DataAdapter
DataSet dataReport = new DataSet();
myDataAdapter.Fill(dataReport,"myPersonalInfoTable  ");
// create a new report from the created CrystalReport
myDataReport myDataReport = new myDataReport();

// set the data source of the report
myDataReport.SetDataSource(dataReport);

// set the report source of the created “crystalReportViewer”
// component to the created report
crystalReportViewer1.ReportSource = myDataReport;

bạn có thể thay đổi dường dẫn mặt định bằng

crystalReportViewer1.ReportSource = @“..\Reports\salesReport.rpt”;

 

Bạn thấy bài viết này như thế nào?: 
Average: 10 (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

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

 
Mẹo chống đau vai khi dùng iPad

Mẹo chống đau vai khi dùng iPad

Nếu như vai bạn ê ẩm sau khi dùng máy tính bảng, bạn có thể khắc phục cảm giác khó chịu này bằng cách thay đổi tư thế cầm máy.

Foxconn tăng 16 đến 25% lương cho công nhân

Foxconn tăng 16 đến 25% lương cho công nhân

Sau một tuần biểu tình, Foxconn - đối tác sản xuất sản phẩm lớn nhất thế giới Apple - đã tăng lương cho các công nhân nhà máy tại Trung Quốc.

Login & Manage Multiple Gmail Accounts Quickly in Chrome

Login & Manage Multiple Gmail Accounts Quickly in Chrome

Recently Google Launched a new Multi Gmail Login feature for its users, which allows them to login different Gmail account from the same browser without signing out...

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

 

Diet con trung