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

 
Apple gặp thất bại khi kiện Galaxy Tab 10.1N tại Đức

Apple gặp thất bại khi kiện Galaxy Tab 10.1N tại Đức

Apple đã kiện Samsung Galaxy Tab 10.1N ở Đức nhưng thật không may tòa án ở đây đã bác đơn kiện của hãng này.

Những điểm bất tiện trên giao diện mới của Gmail

Những điểm bất tiện trên giao diện mới của Gmail

Đối với người sử dụng là doanh nhân hay các doanh nghiệp, Gmail đang dần đánh mất lòng tin của đối tượng người dùng này. Có vẻ như Google đang muốn biến sản phẩm...

Theo dõi email list trong checkout với Drupal Commerce và MailChimp

Theo dõi email list trong checkout với Drupal Commerce và MailChimp

The ability to communicate with your customers is essential when having an online store. One of the ways to do that is to send them valuable information through an email campaign.

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

 

Diet con trung