码迷,mamicode.com
首页 > 编程语言 > 详细

c#语言报表和图表。

时间:2015-06-24 12:25:16      阅读:114      评论:0      收藏:0      [点我收藏+]

标签:

打印报表操作步骤:

1 创建dataset数据集

2 创建rdlc报表文件

3 在窗体中创建reportviewer视图,指定具体数据源

4 给dataset里的datatablede 的对象进行赋值。

参考代码:

 private void Form1_Load(object sender, EventArgs e)

        {

          //连接数据库

            SqlConnection coon = new SqlConnection("server=.;database=master;user=sa;pwd=123");

            SqlCommand cmd = coon.CreateCommand();

            coon.Open();  

           cmd.CommandText = "select*from student ,score where student.sno=score.sno";

            SqlDataReader dr = cmd.ExecuteReader();   

          if (dr.HasRows)

            {

                while (dr.Read ())

                {  

                 //给dataset里的datatable赋值

                    DataRow row = DataSet1.lianjiebiao.NewRow();  

                    row["sno"]=dr["sno"];

                    row["ssex"] = dr["ssex"];

                    row["sname"] = dr["sname"];

                    row["sbirthdy"] = dr["sbirthdy"];

                    row["class"] = dr["class"];

                    row["cno"] = dr["cno"];

                    row["degree"] = dr["degree"];

                    DataSet1.lianjiebiao.Rows.Add(row);    //row为行集合

               }  

           }  

           coon.Close();   

          this.reportViewer1.RefreshReport();

        }

      图表:柱状图,把数据库查出来的数据集放在一个泛型集合里,然后把这个泛型集作为参数赋给柱状图。参考代码如下:

 public partial class Form1 : Form

    {

        private DataClasses1DataContext Context;  //LINQ to SQL类,连接数据库查询

        public Form1()

        {

            InitializeComponent();

            Context = new DataClasses1DataContext();

        }

        private void Form1_Load(object sender, EventArgs e)  

       {

           //car为表名,take(5)只显示其中五列

            List<Car> list = Context.Car.Take(5).ToList();

            //为图表指定数据源

            chart1.DataSource = list;

            chart1.Series["Series1"].XValueMember = "Name";

            chart1.Series["Series1"].YValueMembers = "Oil";

            chart1.Series["Series2"].XValueMember = "Name";

            chart1.Series["Series2"].YValueMembers = "powers";

            //下面是线状图显示

            chart1.Series["Series2"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.FastLine;

        }    

}

    

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

        private void Form1_Load(object sender, EventArgs e)         {             List<Car> list = Context.Car.Take(5).ToList();             //为图表指定数据源             chart1.DataSource = list;             chart1.Series["Series1"].XValueMember = "Name";             chart1.Series["Series1"].YValueMembers = "Oil";             chart1.Series["Series2"].XValueMember = "Name";             chart1.Series["Series2"].YValueMembers = "powers";             //下面是线状图显示             chart1.Series["Series2"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.FastLine;         }     } }

c#语言报表和图表。

标签:

原文地址:http://www.cnblogs.com/275147378abc/p/4597340.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!