PDA

View Full Version : crystal report



mamadelectro
چهارشنبه 07 آذر 1397, 12:44 عصر
سلام به تمامی دوستان . من در برنامه ام یک دیتا بیس با SQL server compact ساخته ام (پسوند فایل *.sdf) و در قسمتی از برنامه برای گزارش گیری توسط crystal report می خواهم از این اطلاعات استفاده کنم . متاسفانه تمامی فیلم های اموزشی برای این کار ، از دیتابیس های با پسوند dbo استفاده کردن . آیا برنامه من امکان پذیر است ؟ باید چطوری برنامه را بنویسم ؟

mamadelectro
سه شنبه 13 آذر 1397, 15:43 عصر
خودم جواب رو پیدا کردم . میزارم تا اگع کسی نیاز داشت استفاده کنه :
Create a Winform and add a button and a CrystalReportViewer control to it.
Add a DataSet (*.xsd file) to your project using add -> New Items in solution explorer. After that, add a DataTable to the DataSet.
then Add columns to DataTable. It's better to name them the same as the columns you are going to display on your report. The number of columns depends on how many columns should be displayed in the Crystal report.
then Add a Crystal Report into the project using add -> New Items and using the Report Wizard, choose ADO.NET DataSets of the Project data source as the data source of the Crystal Report and select the data table you just created in your DataSet, as the selected table of the Crystal Report.
after that Click finish and your columns will automatically be added in CrystalReport.
at the end , Go to the button click event and write these codes in it.



[*=left]private void btnGo_Click(object sender, EventArgs e)
[*=left]{
[*=left] CrReport2 objRpt = new CrReport2();
[*=left] string query = "Select Name,Number from tblInfo"; //Your sql query
[*=left] SqlCeConnection conn =
[*=left] new SqlCeConnection(
[*=left] @"Data Source=|DataDirectory|\myDB.sdf;Persist Security Info=False"); //Your connection
[*=left]
[*=left] SqlCeDataAdapter adepter = new SqlCeDataAdapter(query, conn);
[*=left] DsReport Ds = new DsReport(); //DsReport is my dataset
[*=left]
[*=left] adepter.Fill(Ds, "customer"); //customer is my datatable in dataset
[*=left]
[*=left] objRpt.SetDataSource(Ds);
[*=left] crystalReportViewer1.ReportSource = objRpt;


}