【发布时间】:2012-06-08 15:34:11
【问题描述】:
我创建了一个空白水晶报表
然后使用下面的代码,运行后什么都没有看到。
是否需要在数据集中字段对应的crytsl报告中添加字段对象。 但是我不知道如何在没有通过水晶报表连接的情况下添加。
try
{
string _connectionString = ConfigurationManager.ConnectionStrings["CarParkConnectionString"].ConnectionString;
OleDbConnection connection = null;
try
{
using (connection = new OleDbConnection(_connectionString))
{
//OleDbCommand command = connection.CreateCommand();
string selectsql = "SELECT a.Transaction_Date, a.Card_no, a.Company, a.Credit_Fee, a.Non_Credit_Fee FROM [SELECT Transaction_Date, Card_no, Company, Fee as Credit_Fee, 0 as Non_credit_fee FROM CarPark where IsCredit = true union all SELECT Transaction_Date, Card_no, Company, 0 as Credit_Fee, Fee as Non_credit_fee FROM CarPark where IsCredit = false]. AS a where a.Transaction_Date >= " + Calendar1.SelectedDate.ToShortDateString() + " and a.Transaction_Date <= " + Calendar2.SelectedDate.ToShortDateString();
//command.CommandText = selectsql;
//SetCommandParametersForInsertUpdateTo(carpark, command, error);
connection.Open();
OleDbDataAdapter dataAdapter1 = new OleDbDataAdapter(selectsql, connection);
DataSet ds = new DataSet();
dataAdapter1.Fill(ds, "CarPark");
dataAdapter1.Dispose();
CrystalReport1 objRpt = new CrystalReport1();
objRpt.SetDataSource(ds.Tables[0]);
DailyReport_CrystalReportViewer.EnableParameterPrompt = false;
DailyReport_CrystalReportViewer.ReportSource = objRpt;
DailyReport_CrystalReportViewer.RefreshReport();
}
}
catch (Exception ex)
{
connection.Close();
Error_Label.Text = Error_Label.Text + " " + ex.Message;
}
finally
{
connection.Close();
}
【问题讨论】: