如何动态生成水晶报表(ASP.NET)

今天终于完成了在Web 窗体下的动态生成报表,但是问题还是比较多的。比如报表的格式设计,边框等问题还没有解决。请各位高手指点。
我是用水晶报表中的公式字段和参数字段完成动太报表开发的。
具体的代码如下:
private void Button1_Click(object sender, System.EventArgs e)
  {
   string ConnectionString ="";
   string sqlString = "";
   string FieldString = "";
   //string [] FieldString;
   string[] FieldArray;
   int i,j;
   ParameterFields ParamFields =new ParameterFields();//参数字段集合
   ParameterField ParamField;//参数字段
   ParameterDiscreteValue DiscreteVal = new ParameterDiscreteValue();
   if(CheckBox1.Checked==true)
    FieldString=CheckBox1.Text;
   if(CheckBox2.Checked==true)
    FieldString = FieldString +"," + CheckBox2.Text;
   if(CheckBox3.Checked==true)
    FieldString = FieldString + "," +CheckBox3.Text;
   if(CheckBox4.Checked==true)
    FieldString = FieldString + "," +CheckBox4.Text;
   if(FieldString.Substring(0,1)==",")
    FieldString=FieldString.Substring(1,FieldString.Length -1);
   FieldArray=FieldString.Split((char)',');
   ConnectionString="server=lwb;uid=sa;pwd=;database=northwind;";
   SqlConnection mycon = new SqlConnection(ConnectionString);
   sqlString = "select "+ FieldString +" from orders";
   SqlDataAdapter da=new SqlDataAdapter(sqlString,mycon);
   DataSet ds = new DataSet();
   da.Fill(ds,"orders");
   CrystalReport1 oRp = new CrystalReport1();
   int temp = FieldArray.Length;
   for ( i = 0; i< temp; i++)
   {
    ParamField = new ParameterField();
    ParamField.ParameterFieldName = "myParaField" + (i + 1).ToString();
    DiscreteVal = new ParameterDiscreteValue();
    DiscreteVal.Value = FieldArray[i];
    ParamField.CurrentValues.Add(DiscreteVal);
    ParamFields.Add(ParamField);     
   
    oRp.DataDefinition.FormulaFields["myField" + (i + 1).ToString()].Text = "{orders." + FieldArray[i] + "}";
   }
   for ( j = i + 1; j<= 6; j++)
   {
    ParamField = new ParameterField();
    ParamField.ParameterFieldName = "myParaField" + (j).ToString();
    ParamFields.Add(ParamField);
    DiscreteVal = new ParameterDiscreteValue();
    DiscreteVal.Value = "";
    ParamField.CurrentValues.Add(DiscreteVal);
    ParamFields.Add(ParamField);     
   }
   CrystalReportViewer1.ParameterFieldInfo = ParamFields;
   oRp.SetDataSource(ds);
   CrystalReportViewer1.ReportSource = oRp;
  }

转载于:https://www.cnblogs.com/steven_lwb/archive/2005/08/17/216997.html

  • 0
    点赞
  • 0
    评论
  • 0
    收藏
  • 扫一扫,分享海报

参与评论 您还未登录,请先 登录 后发表或查看评论
©️2022 CSDN 皮肤主题:大白 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值