hi dear,
private void FxDatagried()
{
SqlConnection objConn1 = new SqlConnection("Data Source= Sql Server Name ;Initial Catalog= Database Name ;user id=sa; password=123;");
string sql = "SELECT * FROM TableName ";
SqlCommand cmd = new SqlCommand(sql, objConn1);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
objConn1.Open();
da.Fill(dt);
dataGridView.DataSource = dt;
objConn1.Close();
}
private void FxPrint()
{
printDocument1.Print();
}
private void printDocument1_PrintPage(object sender,System.Drawing.Printing.PrintPageEventArgs e)
{
Bitmap bm = new Bitmap(this.dataGridView.Width, this.dataGridView.Height);
this.dataGridView.DrawToBitmap(bm, new Rectangle(0, 0, this.dataGridView.Width, this.dataGridView.Height));
e.Graphics.DrawImage(bm, 0, 0);
}