标题:c#如何打印出查询的内容
取消只看楼主
lukebc
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:3
帖 子:74
专家分:32
注 册:2009-8-18
结帖率:71.43%
 问题点数:0 回复次数:1 
c#如何打印出查询的内容
以下代码是把所有的记录打印出来,但我要的是怎么打印出查询出的内容,最好能够将查询结果的值传过去,应该怎么改
private void button3_Click(object sender, EventArgs e)
        {
            printDialog1.ShowDialog();  //设置打印文档
            printPreviewDialog1.Document = this.printDocument1;
            printPreviewDialog1.ShowDialog();
        }

        private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {

            SqlConnection conn = new SqlConnection();
            conn.ConnectionString = "server=LUKE\\SQLEXPRESS;uid=sa;pwd=sa;database=luke";
            conn.Open();
            DataTable dt = new DataTable("resouce");
            dt.Clear();
            SqlDataAdapter adp = new SqlDataAdapter("select * from text1", conn);
            adp.Fill(dt);
            dataGridView1.DataSource = dt.DefaultView;

            int r = 0;
            int c = 20;
            for (int i = 0; i < dt.Rows.Count; i++)
            {

                for (int j = 0; j < dt.Columns.Count; j++)
                {

                    e.Graphics.DrawString(dt.Rows[i][j].ToString(), new Font("宋体", 10, FontStyle.Regular), Brushes.Black, r, c);
                    r = r + 60;

                }
                r = 0;
                c += 20;

            }
        }
搜索更多相关主题的帖子: private 如何 记录 最好 
2016-09-05 15:03
lukebc
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:3
帖 子:74
专家分:32
注 册:2009-8-18
得分:0 
我知道啊,但是我查询本来有个按钮,但这样做等于我又查询了一遍,我是需要知道,怎么打我查询的值,传到打印事件里,不用再查询
2016-09-06 08:37



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-468516-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.409051 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved