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;
}
}