PDA

View Full Version : Tạo Crytal report đường dẫn động.



nguyentientai
17-06-2010, 09:27 PM
Chào các bạn, tớ đang làm bài báo cáo tốt nghiệp, có 1 chỗ vướng mắc mong các bạn xem hộ.
Mình tạo 1 báo cáo bằng Crytal report và viết code cho form hiển thị report là:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;

namespace WindowsApplication1
{
public partial class Form1 : Form
{
private OleDbConnection con;

#region "Ket noi"
private void connect()
{
//string cn ="Provider = Microsoft.Jet.OLEDB.4.0 ;" +
// "Data Source =" + AppPath() +@"\Data\QuanlyHH.mdb;" +
// "User ID = Admin;" + "Persist Security Info=False";
string cn = "Provider = Microsoft.Jet.OLEDB.4.0 ;" +
"Data Source =QuanlyHH.mdb";

try
{
con = new OleDbConnection(cn);
con.Open();
}
catch (Exception ex)
{
MessageBox.Show("Không kết nối được cơ sở dữ liệu", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
#endregion

private string AppPath()
{
return Application.StartupPath.Substring(0,Application.St artupPath.Length - 10);
}

public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
connect();
DataSet ds = new DataSet();
OleDbDataAdapter da = new OleDbDataAdapter("Select * From DMHH", con);
da.Fill(ds);
ReportDocument rpt = new ReportDocument();
rpt.Load(AppPath() +@"\CrystalReport2.rpt");
rpt.SetDataSource(ds);
this.crp.ReportSource = rpt;
this.crp.Refresh();
this.crp.Zoom(90);
con.Close();
}
}
}
Nếu để phần mềm nơi đường dẫn mình viết thì chạy bình thường, còn khi copy sang máy khác hay ổ khác thì báo lỗi đường dẫn như thế này:
http://img139.imageshack.us/img139/1416/71956092sf6.jpg
Nếu ấn Finish thì nó báo
http://img89.imageshack.us/img89/3253/17213970hm4.jpg
Mình rất mong các bạn giúp đỡ, cảm ơn các bạn nhiều...
Mình đang cần 1 người để học hỏi kinh nghiệm về Tin học, mình rất muốn làm quen, qua số điện thoại 0974500449 hoặc email: tientaiit@yahoo.com
Thanks