在WinForm下,Crystal Report的打印是通过代码实现的,它的代码非常讲究顺序:
下面给你一个例子,你自己把它改为你要的。
string ConnText="database=bccsdb;uid=sa";
SqlConnection Conn=new SqlConnection();
Conn.ConnectionString=ConnText;
try
{
Conn.Open();
}
catch(SqlException sqlex)
{
MessageBox.Show("出错原因:"+sqlex.Message,"出错",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
finally
{
Conn.Close();
}
if(this.radioButton1.Checked)
{
try
{
this.Conn1.Open();
string SelectText="SELECT UnitNo, DepositBalance, CreditBalance, DepositAverageBrow, CreditAverageBrow, DepositCreditCollate, DepositInterestRate, CreditInterestRate, RemoveIncomeBankroll, RemoveIncomeInterestRate, StairPreparativeBrow, StairPreparativeBrowInterestRate, SecondPreparativeBrow, SecondPreparativeBrowInterestRate, Cess, ChargeRate, DailyProfit, DayCount, DepositProfitRate, CreditProfitRate FROM [ThenStat.]";
SqlCommand Select=new SqlCommand();
Select.CommandText=SelectText;
Select.Connection=this.Conn1;
this.SqlDa1.SelectCommand=Select;
SqlDa1.Fill(this.ReportThenStat);
RptThenStat Rpt=new RptThenStat();
Rpt.SetDataSource(this.ReportThenStat);
this.crystalReportViewer1.ReportSource=Rpt;
}
catch(SqlException sqlex)
{
MessageBox.Show(sqlex.Message,"出错",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
finally
{
Conn1.Close();
}
}
下面给你一个例子,你自己把它改为你要的。
string ConnText="database=bccsdb;uid=sa";
SqlConnection Conn=new SqlConnection();
Conn.ConnectionString=ConnText;
try
{
Conn.Open();
}
catch(SqlException sqlex)
{
MessageBox.Show("出错原因:"+sqlex.Message,"出错",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
finally
{
Conn.Close();
}
if(this.radioButton1.Checked)
{
try
{
this.Conn1.Open();
string SelectText="SELECT UnitNo, DepositBalance, CreditBalance, DepositAverageBrow, CreditAverageBrow, DepositCreditCollate, DepositInterestRate, CreditInterestRate, RemoveIncomeBankroll, RemoveIncomeInterestRate, StairPreparativeBrow, StairPreparativeBrowInterestRate, SecondPreparativeBrow, SecondPreparativeBrowInterestRate, Cess, ChargeRate, DailyProfit, DayCount, DepositProfitRate, CreditProfitRate FROM [ThenStat.]";
SqlCommand Select=new SqlCommand();
Select.CommandText=SelectText;
Select.Connection=this.Conn1;
this.SqlDa1.SelectCommand=Select;
SqlDa1.Fill(this.ReportThenStat);
RptThenStat Rpt=new RptThenStat();
Rpt.SetDataSource(this.ReportThenStat);
this.crystalReportViewer1.ReportSource=Rpt;
}
catch(SqlException sqlex)
{
MessageBox.Show(sqlex.Message,"出错",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
finally
{
Conn1.Close();
}
}
解决方案 »
- vs2008打包部署 怎么做再次安装的时候会提醒安装,修复还是卸载
- 下面这段代码不是很清楚,大家能帮我看下吗?谢谢了
- 如何用c# 构造一颗二叉树
- 如何在Datagridview中增加一个属性
- 请问能不能调用Google的语言工具进行中英文翻译?如何调用?
- C# Graphics对象调用Dispose()方法后,为什么绘制的图像还在?
- 请高手帮忙看看,谢谢了
- 急求 100 拖动图片框问题
- 关于DropDownList与从数据库中调用的数据匹配问题?
- 全局变量放在哪里声明好啊
- 哪里有VS.NET2003下载?哪位能帮个忙?
- 请问在VC#中如何导入*.bmp的图像资源文件,并在程序运行中将图中的某一部分在窗体的指定位置上显示出来?
在完成这些功能以后,在CrystalReportView中的工具栏上有一个打印按钮,你可以单击那一个按扭就可以进行打印了。对报表的页面进行设置是在报表设计的视图中完成的。