在C#里实现DATAGRID的打印预览和打印
很多人都在论坛里问,如何实现DATAGRID的打印预览和打印,现在我就把这方面的源代码告诉大家。这段代码也花费了我1个晚上的时间,呵呵!数据库是基于sql server2000自带的northwind。源代码如下:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.OleDb;
namespace DataGridPrint
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.DataGrid dgTest;
private System.Windows.Forms.Button btnFillDataGrid;
private System.Windows.Forms.MainMenu mnuFile;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem miPrintPreview;
private System.Windows.Forms.MenuItem miPrint;
private System.Windows.Forms.MenuItem menuItem4;
private System.Windows.Forms.MenuItem miExit;
private System.Windows.Forms.DataGridTableStyle dgtsCustomers;
private System.Windows.Forms.DataGridTextBoxColumn dataGridTextBoxColumn1;
private System.Windows.Forms.DataGridTextBoxColumn dataGridTextBoxColumn2;
private System.Windows.Forms.DataGridTextBoxColumn dataGridTextBoxColumn3;
private System.Windows.Forms.DataGridTextBoxColumn dataGridTextBoxColumn4;
private System.Windows.Forms.DataGridTextBoxColumn dataGridTextBoxColumn6;
private System.Windows.Forms.DataGridTextBoxColumn dataGridTextBoxColumn7;
private System.Windows.Forms.DataGridTextBoxColumn dataGridTextBoxColumn8;
private System.Windows.Forms.DataGridTextBoxColumn dataGridTextBoxColumn9;
private System.Windows.Forms.DataGridTextBoxColumn dataGridTextBoxColumn10;
private System.Windows.Forms.DataGridTextBoxColumn dataGridTextBoxColumn11;
private System.Windows.Forms.DataGridTextBoxColumn dataGridTextBoxColumn5;
private System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
private System.Data.SqlClient.SqlCommand sqlSelectCommand1;
private System.Data.SqlClient.SqlCommand sqlInsertCommand1;
private System.Data.SqlClient.SqlCommand sqlUpdateCommand1;
private System.Data.SqlClient.SqlCommand sqlDeleteCommand1;
private System.Data.SqlClient.SqlConnection sqlConnection1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.panel1 = new System.Windows.Forms.Panel();
this.dgTest = new System.Windows.Forms.DataGrid();
this.dgtsCustomers = new System.Windows.Forms.DataGridTableStyle();
this.dataGridTextBoxColumn1 = new System.Windows.Forms.DataGridTextBoxColumn();
this.dataGridTextBoxColumn2 = new System.Windows.Forms.DataGridTextBoxColumn();
this.dataGridTextBoxColumn3 = new System.Windows.Forms.DataGridTextBoxColumn();
this.dataGridTextBoxColumn4 = new System.Windows.Forms.DataGridTextBoxColumn();
this.dataGridTextBoxColumn5 = new System.Windows.Forms.DataGridTextBoxColumn();
this.dataGridTextBoxColumn6 = new System.Windows.Forms.DataGridTextBoxColumn();
this.dataGridTextBoxColumn7 = new System.Windows.Forms.DataGridTextBoxColumn();
this.dataGridTextBoxColumn8 = new System.Windows.Forms.DataGridTextBoxColumn();
this.dataGridTextBoxColumn9 = new System.Windows.Forms.DataGridTextBoxColumn();
this.dataGridTextBoxColumn10 = new System.Windows.Forms.DataGridTextBoxColumn();
this.dataGridTextBoxColumn11 = new System.Windows.Forms.DataGridTextBoxColumn();
this.btnFillDataGrid = new System.Windows.Forms.Button();
this.mnuFile = new System.Windows.Forms.MainMenu();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.miPrintPreview = new System.Windows.Forms.MenuItem();
this.miPrint = new System.Windows.Forms.MenuItem();
this.menuItem4 = new System.Windows.Forms.MenuItem();
this.miExit = new System.Windows.Forms.MenuItem();
this.sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter();
this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlInsertCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlUpdateCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlDeleteCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
this.panel1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dgTest)).BeginInit();
this.SuspendLayout();
//
// panel1
//
this.panel1.Anchor = (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right);
this.panel1.Controls.AddRange(new System.Windows.Forms.Control[] {
this.dgTest});
this.panel1.Location = new System.Drawing.Point(0, 9);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(788, 398);
this.panel1.TabIndex = 1;
//
// dgTest
//
this.dgTest.DataMember = "";
this.dgTest.Dock = System.Windows.Forms.DockStyle.Fill;
this.dgTest.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dgTest.Name = "dgTest";
this.dgTest.Size = new System.Drawing.Size(788, 398);
this.dgTest.TabIndex = 0;
this.dgTest.TableStyles.AddRange(new System.Windows.Forms.DataGridTableStyle[] {
this.dgtsCustomers});
//
// dgtsCustomers
//
this.dgtsCustomers.DataGrid = this.dgTest;
this.dgtsCustomers.GridColumnStyles.AddRange(new System.Windows.Forms.DataGridColumnStyle[] {
this.dataGridTextBoxColumn1,
this.dataGridTextBoxColumn2,
this.dataGridTextBoxColumn3,
this.dataGridTextBoxColumn4,
this.dataGridTextBoxColumn5,
this.dataGridTextBoxColumn6,
this.dataGridTextBoxColumn7,
this.dataGridTextBoxColumn8,
this.dataGridTextBoxColumn9,
this.dataGridTextBoxColumn10,
this.dataGridTextBoxColumn11});
this.dgtsCustomers.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dgtsCustomers.MappingName = "Customers";
this.dgtsCustomers.ReadOnly = true;
//
// dataGridTextBoxColumn1
//
this.dataGridTextBoxColumn1.Format = "";
this.dataGridTextBoxColumn1.FormatInfo = null;
this.dataGridTextBoxColumn1.HeaderText = "Customer Id";
this.dataGridTextBoxColumn1.MappingName = "CustomerId";
this.dataGridTextBoxColumn1.NullText = "";
this.dataGridTextBoxColumn1.Width = 75;
//
// dataGridTextBoxColumn2
//
this.dataGridTextBoxColumn2.Format = "";
this.dataGridTextBoxColumn2.FormatInfo = null;
this.dataGridTextBoxColumn2.HeaderText = "Company Name";
this.dataGridTextBoxColumn2.MappingName = "CompanyName";
this.dataGridTextBoxColumn2.NullText = "";
this.dataGridTextBoxColumn2.Width = 200;
//
// dataGridTextBoxColumn3
//
this.dataGridTextBoxColumn3.Format = "";
this.dataGridTextBoxColumn3.FormatInfo = null;
this.dataGridTextBoxColumn3.HeaderText = "Contact Name";
this.dataGridTextBoxColumn3.MappingName = "ContactName";
this.dataGridTextBoxColumn3.NullText = "";
this.dataGridTextBoxColumn3.Width = 125;
//
// dataGridTextBoxColumn4
//
this.dataGridTextBoxColumn4.Format = "";
this.dataGridTextBoxColumn4.FormatInfo = null;
this.dataGridTextBoxColumn4.HeaderText = "Contact Title";
this.dataGridTextBoxColumn4.MappingName = "ContactTitle";
this.dataGridTextBoxColumn4.NullText = "";
this.dataGridTextBoxColumn4.Width = 170;
//
// dataGridTextBoxColumn5
//
this.dataGridTextBoxColumn5.Format = "";
this.dataGridTextBoxColumn5.FormatInfo = null;
this.dataGridTextBoxColumn5.HeaderText = "Address";
this.dataGridTextBoxColumn5.MappingName = "Address";
this.dataGridTextBoxColumn5.NullText = "";
this.dataGridTextBoxColumn5.Width = 250;
//
// dataGridTextBoxColumn6
//
this.dataGridTextBoxColumn6.Format = "";
this.dataGridTextBoxColumn6.FormatInfo = null;
this.dataGridTextBoxColumn6.HeaderText = "City";
this.dataGridTextBoxColumn6.MappingName = "City";
this.dataGridTextBoxColumn6.NullText = "";
this.dataGridTextBoxColumn6.Width = 150;
//
// dataGridTextBoxColumn7
//
this.dataGridTextBoxColumn7.Format = "";
this.dataGridTextBoxColumn7.FormatInfo = null;
this.dataGridTextBoxColumn7.HeaderText = "Region";
this.dataGridTextBoxColumn7.MappingName = "Region";
this.dataGridTextBoxColumn7.NullText = "";
this.dataGridTextBoxColumn7.Width = 150;
//
// dataGridTextBoxColumn8
//
this.dataGridTextBoxColumn8.Format = "";
this.dataGridTextBoxColumn8.FormatInfo = null;
this.dataGridTextBoxColumn8.HeaderText = "Postal Code";
this.dataGridTextBoxColumn8.MappingName = "PostalCode";
this.dataGridTextBoxColumn8.NullText = "";
this.dataGridTextBoxColumn8.Width = 150;
//
// dataGridTextBoxColumn9
//
this.dataGridTextBoxColumn9.Format = "";
this.dataGridTextBoxColumn9.FormatInfo = null;
this.dataGridTextBoxColumn9.HeaderText = "Country";
this.dataGridTextBoxColumn9.MappingName = "Country";
this.dataGridTextBoxColumn9.NullText = "";
this.dataGridTextBoxColumn9.Width = 125;
//
// dataGridTextBoxColumn10
//
this.dataGridTextBoxColumn10.Format = "";
this.dataGridTextBoxColumn10.FormatInfo = null;
this.dataGridTextBoxColumn10.HeaderText = "Phone";
this.dataGridTextBoxColumn10.MappingName = "Phone";
this.dataGridTextBoxColumn10.NullText = "";
this.dataGridTextBoxColumn10.Width = 125;
//
// dataGridTextBoxColumn11
//
this.dataGridTextBoxColumn11.Format = "";
this.dataGridTextBoxColumn11.FormatInfo = null;
this.dataGridTextBoxColumn11.HeaderText = "Fax";
this.dataGridTextBoxColumn11.MappingName = "Fax";
this.dataGridTextBoxColumn11.NullText = "";
this.dataGridTextBoxColumn11.Width = 125;
//
// btnFillDataGrid
//
this.btnFillDataGrid.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right);
this.btnFillDataGrid.Location = new System.Drawing.Point(645, 426);
this.btnFillDataGrid.Name = "btnFillDataGrid";
this.btnFillDataGrid.Size = new System.Drawing.Size(133, 28);
this.btnFillDataGrid.TabIndex = 2;
this.btnFillDataGrid.Text = "&Fill DataGrid";
this.btnFillDataGrid.Click += new System.EventHandler(this.btnFillDataGrid_Click);
//
// mnuFile
//
this.mnuFile.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem1});
//
// menuItem1
//
this.menuItem1.Index = 0;
this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.miPrintPreview,
this.miPrint,
this.menuItem4,
this.miExit});
this.menuItem1.Text = "&File";
//
// miPrintPreview
//
this.miPrintPreview.Index = 0;
this.miPrintPreview.Text = "Print Pre&view";
this.miPrintPreview.Click += new System.EventHandler(this.miPrintPreview_Click);
//
// miPrint
//
this.miPrint.Index = 1;
this.miPrint.Text = "&Print";
this.miPrint.Click += new System.EventHandler(this.miPrint_Click);
//
// menuItem4
//
this.menuItem4.Index = 2;
this.menuItem4.Text = "-";
//
// miExit
//
this.miExit.Index = 3;
this.miExit.Text = "E&xit";
this.miExit.Click += new System.EventHandler(this.miExit_Click);
//
// sqlDataAdapter1
//
this.sqlDataAdapter1.DeleteCommand = this.sqlDeleteCommand1;
this.sqlDataAdapter1.InsertCommand = this.sqlInsertCommand1;
this.sqlDataAdapter1.SelectCommand = this.sqlSelectCommand1;
this.sqlDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table", "Customers", new System.Data.Common.DataColumnMapping[] {
new System.Data.Common.DataColumnMapping("CustomerID", "CustomerID"),
new System.Data.Common.DataColumnMapping("CompanyName", "CompanyName"),
new System.Data.Common.DataColumnMapping("ContactName", "ContactName"),
new System.Data.Common.DataColumnMapping("ContactTitle", "ContactTitle"),
new System.Data.Common.DataColumnMapping("Address", "Address"),
new System.Data.Common.DataColumnMapping("City", "City"),
new System.Data.Common.DataColumnMapping("Region", "Region"),
new System.Data.Common.DataColumnMapping("PostalCode", "PostalCode"),
new System.Data.Common.DataColumnMapping("Country", "Country"),
new System.Data.Common.DataColumnMapping("Phone", "Phone"),
new System.Data.Common.DataColumnMapping("Fax", "Fax")})});
this.sqlDataAdapter1.UpdateCommand = this.sqlUpdateCommand1;
//
// sqlSelectCommand1
//
this.sqlSelectCommand1.CommandText = "SELECT CustomerID, CompanyName, ContactName, ContactTitle, Address, City, Region," +
" PostalCode, Country, Phone, Fax FROM Customers";
this.sqlSelectCommand1.Connection = this.sqlConnection1;
//
// sqlInsertCommand1
//
this.sqlInsertCommand1.CommandText = @"INSERT INTO Customers(CustomerID, CompanyName, ContactName, ContactTitle, Address, City, Region, PostalCode, Country, Phone, Fax) VALUES (@CustomerID, @CompanyName, @ContactName, @ContactTitle, @Address, @City, @Region, @PostalCode, @Country, @Phone, @Fax); SELECT CustomerID, CompanyName, ContactName, ContactTitle, Address, City, Region, PostalCode, Country, Phone, Fax FROM Customers WHERE (CustomerID = @CustomerID)";
this.sqlInsertCommand1.Connection = this.sqlConnection1;
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@CustomerID", System.Data.SqlDbType.NVarChar, 5, "CustomerID"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@CompanyName", System.Data.SqlDbType.NVarChar, 40, "CompanyName"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ContactName", System.Data.SqlDbType.NVarChar, 30, "ContactName"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ContactTitle", System.Data.SqlDbType.NVarChar, 30, "ContactTitle"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Address", System.Data.SqlDbType.NVarChar, 60, "Address"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@City", System.Data.SqlDbType.NVarChar, 15, "City"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Region", System.Data.SqlDbType.NVarChar, 15, "Region"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@PostalCode", System.Data.SqlDbType.NVarChar, 10, "PostalCode"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Country", System.Data.SqlDbType.NVarChar, 15, "Country"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Phone", System.Data.SqlDbType.NVarChar, 24, "Phone"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Fax", System.Data.SqlDbType.NVarChar, 24, "Fax"));
//
// sqlUpdateCommand1
//
this.sqlUpdateCommand1.CommandText = @"UPDATE Customers SET CustomerID = @CustomerID, CompanyName = @CompanyName, ContactName = @ContactName, ContactTitle = @ContactTitle, Address = @Address, City = @City, Region = @Region, PostalCode = @PostalCode, Country = @Country, Phone = @Phone, Fax = @Fax WHERE (CustomerID = @Original_CustomerID) AND (Address = @Original_Address OR @Original_Address IS NULL AND Address IS NULL) AND (City = @Original_City OR @Original_City IS NULL AND City IS NULL) AND (CompanyName = @Original_CompanyName) AND (ContactName = @Original_ContactName OR @Original_ContactName IS NULL AND ContactName IS NULL) AND (ContactTitle = @Original_ContactTitle OR @Original_ContactTitle IS NULL AND ContactTitle IS NULL) AND (Country = @Original_Country OR @Original_Country IS NULL AND Country IS NULL) AND (Fax = @Original_Fax OR @Original_Fax IS NULL AND Fax IS NULL) AND (Phone = @Original_Phone OR @Original_Phone IS NULL AND Phone IS NULL) AND (PostalCode = @Original_PostalCode OR @Original_PostalCode IS NULL AND PostalCode IS NULL) AND (Region = @Original_Region OR @Original_Region IS NULL AND Region IS NULL); SELECT CustomerID, CompanyName, ContactName, ContactTitle, Address, City, Region, PostalCode, Country, Phone, Fax FROM Customers WHERE (CustomerID = @CustomerID)";
this.sqlUpdateCommand1.Connection = this.sqlConnection1;
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@CustomerID", System.Data.SqlDbType.NVarChar, 5, "CustomerID"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@CompanyName", System.Data.SqlDbType.NVarChar, 40, "CompanyName"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ContactName", System.Data.SqlDbType.NVarChar, 30, "ContactName"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ContactTitle", System.Data.SqlDbType.NVarChar, 30, "ContactTitle"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Address", System.Data.SqlDbType.NVarChar, 60, "Address"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@City", System.Data.SqlDbType.NVarChar, 15, "City"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Region", System.Data.SqlDbType.NVarChar, 15, "Region"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@PostalCode", System.Data.SqlDbType.NVarChar, 10, "PostalCode"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Country", System.Data.SqlDbType.NVarChar, 15, "Country"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Phone", System.Data.SqlDbType.NVarChar, 24, "Phone"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Fax", System.Data.SqlDbType.NVarChar, 24, "Fax"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_CustomerID", System.Data.SqlDbType.NVarChar, 5, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "CustomerID", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Address", System.Data.SqlDbType.NVarChar, 60, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Address", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_City", System.Data.SqlDbType.NVarChar, 15, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "City", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_CompanyName", System.Data.SqlDbType.NVarChar, 40, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "CompanyName", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_ContactName", System.Data.SqlDbType.NVarChar, 30, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "ContactName", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_ContactTitle", System.Data.SqlDbType.NVarChar, 30, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "ContactTitle", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Country", System.Data.SqlDbType.NVarChar, 15, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Country", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Fax", System.Data.SqlDbType.NVarChar, 24, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Fax", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Phone", System.Data.SqlDbType.NVarChar, 24, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Phone", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_PostalCode", System.Data.SqlDbType.NVarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "PostalCode", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Region", System.Data.SqlDbType.NVarChar, 15, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Region", System.Data.DataRowVersion.Original, null));
//
// sqlDeleteCommand1
//
this.sqlDeleteCommand1.CommandText = @"DELETE FROM Customers WHERE (CustomerID = @Original_CustomerID) AND (Address = @Original_Address OR @Original_Address IS NULL AND Address IS NULL) AND (City = @Original_City OR @Original_City IS NULL AND City IS NULL) AND (CompanyName = @Original_CompanyName) AND (ContactName = @Original_ContactName OR @Original_ContactName IS NULL AND ContactName IS NULL) AND (ContactTitle = @Original_ContactTitle OR @Original_ContactTitle IS NULL AND ContactTitle IS NULL) AND (Country = @Original_Country OR @Original_Country IS NULL AND Country IS NULL) AND (Fax = @Original_Fax OR @Original_Fax IS NULL AND Fax IS NULL) AND (Phone = @Original_Phone OR @Original_Phone IS NULL AND Phone IS NULL) AND (PostalCode = @Original_PostalCode OR @Original_PostalCode IS NULL AND PostalCode IS NULL) AND (Region = @Original_Region OR @Original_Region IS NULL AND Region IS NULL)";
this.sqlDeleteCommand1.Connection = this.sqlConnection1;
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_CustomerID", System.Data.SqlDbType.NVarChar, 5, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "CustomerID", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Address", System.Data.SqlDbType.NVarChar, 60, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Address", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_City", System.Data.SqlDbType.NVarChar, 15, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "City", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_CompanyName", System.Data.SqlDbType.NVarChar, 40, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "CompanyName", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_ContactName", System.Data.SqlDbType.NVarChar, 30, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "ContactName", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_ContactTitle", System.Data.SqlDbType.NVarChar, 30, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "ContactTitle", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Country", System.Data.SqlDbType.NVarChar, 15, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Country", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Fax", System.Data.SqlDbType.NVarChar, 24, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Fax", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Phone", System.Data.SqlDbType.NVarChar, 24, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Phone", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_PostalCode", System.Data.SqlDbType.NVarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "PostalCode", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Region", System.Data.SqlDbType.NVarChar, 15, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Region", System.Data.DataRowVersion.Original, null));
//
// sqlConnection1
//
this.sqlConnection1.ConnectionString = "data source=QIEYJ;initial catalog=Northwind;persist security info=False;user id=s" +
"a;workstation id=QIEYJ;packet size=4096";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(788, 463);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.btnFillDataGrid,
this.panel1});
this.Menu = this.mnuFile;
this.Name = "Form1";
this.Text = "DataGrid Print Sample";
this.panel1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dgTest)).EndInit();
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void btnFillDataGrid_Click(object sender, System.EventArgs e)
{
DataTable dt = new DataTable("Customers");
try
{
sqlDataAdapter1.Fill(dt);
dgTest.DataSource = dt;
}
catch (System.Exception ex)
{
MessageBox.Show(this,ex.Message);
}
}
private void miPrintPreview_Click(object sender, System.EventArgs e)
{
DataGridPrintDocument dpd = new DataGridPrintDocument(dgTest);
dpd.ColumnHeaderFont=new Font("Arial",8,FontStyle.Bold);
dpd.DefaultPageSettings.Landscape = true;
PrintPreviewDialog PrintPrevDlg=new PrintPreviewDialog();
PrintPrevDlg.Document = dpd;
PrintPrevDlg.ShowDialog(this);
}
private void miPrint_Click(object sender, System.EventArgs e)
{
DataGridPrintDocument dpd = new DataGridPrintDocument(dgTest);
dpd.DefaultPageSettings.Landscape = true;
PrintDialog PrintDlg=new PrintDialog();
PrintDlg.Document = dpd;
DialogResult dlgresult=PrintDlg.ShowDialog(this);
if (dlgresult==DialogResult.OK)
dpd.Print();
}
private void miExit_Click(object sender, System.EventArgs e)
{
Application.Exit();
}
}
}
相关文章:

ORACLE SQL: 经典查询练手第二篇
本文使用的实例表结构与表的数据如下: scott.emp员工表结构如下: SQL> DESC SCOTT.EMP;Name Type Nullable Default Comments -------- ------------ -------- ------- -------- EMPNO NUMBER(4) 员工编号 ENAME…

第十三届光华工程科技奖名单揭晓!这40位专家和1个团体获奖
11月8日,第十三届光华工程科技奖揭晓仪式在北京隆重举行。工程科技是推动人类进步的发动机,是产业革命、经济发展、社会进步的有力杠杆。光华工程科技奖由中国工程院主管,目前已是第十三届,被誉为“中国工程界最高奖项”ÿ…

【C#公共帮助类】给大家分享一些加密算法 (DES、HashCode、RSA、AES等)
http://www.cnblogs.com/yuangang/p/5466068.html转载于:https://www.cnblogs.com/daming1233/p/6704562.html

MongoDB的备份(mongodump)与恢复(mongorestore)
为什么80%的码农都做不了架构师?>>> 不用多想,数据的备份无论什么时候都是必须的,尤其是重要数据。 MongoDB也提供了备份和恢复的功能,分别是MongoDB下载目录下的mongdump.exe和mongorestore.exe文件。 先介绍下命令…

Windows 2000/XP 注册表终极修改(转载)
Microsoft Windows 2000/XP 是一个强大的操作系统,为我们提供了以往Windows 9x从未有过的安全性能,可是你是否感觉某些地方的设置还不够呢,这里就对Windows 2000 的注册表进行一些修改来达到我们的目的。 一、修改开始菜单和任务栏 由于以往不…

百度CTO王海峰获“光华工程科技奖”,深耕自然语言处理近30年
11月8日,第十三届光华工程科技奖揭晓仪式在北京举行。该奖项被誉为“中国工程界最高奖项”,旨在对我国工程科技及管理领域做出杰出贡献的科学家、工程师进行表彰。百度CTO王海峰因其在人工智能领域、尤其是自然语言处理领域的卓越贡献,成为AI…

python自定义库文件路径
各有各的小烦恼,各有的小期待 这是人家私事,不要大嘴巴 在Pycharm中import whois时,总是失败 原因是安装了python3.x相关操作过程,将环境变量path中关于Python的配置c:\Python27和c:\Python27\Scripts都删除,pycharm中…

开机BIOS语言(转载)
开机自检时出现问题后会出现各种各样的英文短句,短句中包含了非常重要的信息,读懂这些信息可以自己解决一些小问题,可是这些英文难倒了一部分朋友,下面是一些常见的BIOS短句的解释,大家可以参考一下。 1.CMOS battery …
参与开源项目,结识技术大牛!CSDN“开源加速器计划”招募志愿者啦!
什么是“CSDN开源加速器计划”?纵观近 30 年的科技创新,开源已成为全球技术应用和行业数字化发展的基石,尤其最近几年,开源的商业化得到了极大突破,开源正在成为全球科技的强劲驱动力。在开源生态中,开发者…

破解CentOS的root密码(救援模式无密码)
开机后,在倒数读秒的时候按任意键、跳转画面后,再按E键,进入如下界面: 此时把光标定位到第二行,再按E键(意为:在启动顺序里编辑这条命令),如下图,此时输入“空…

第九—十三单元练习
<<<第九单元练习>>>1.在desktop主机中建立用户westos,并设定其密码为westoslinux2.配置desktop中的sshd服务要求如下:*)设定sshd服务只允许westos用户可以被访问使用*)创建westos用户的key认证方式*)…
用 Java 训练深度学习模型,原来这么简单
作者 | DJL-Keerthan&Lanking来源 | HelloGitHub头图 | CSDN下载自东方IC前言很长时间以来,Java 都是一个很受企业欢迎的编程语言。得益于丰富的生态以及完善维护的包和框架,Java 拥有着庞大的开发者社区。尽管深度学习应用的不断演进和落地…

重装操作系统的20条原则(转载)
系统是否需重装,三条法则帮你忙: 如果系统出现以下三种情况之一,应该是你考虑重装系统的时候了: 1)系统运行效率变得低下,垃圾文件充斥硬盘且散乱分布又不便于集中清理和自动清理; 2)系统频繁出错&…

RKLayout
2019独角兽企业重金招聘Python工程师标准>>> RKLayout 是 iOS 上一个简单的布局管理器 转载:http://www.adobex.com/ios/source/details/00000978.htm 转载于:https://my.oschina.net/u/868244/blog/107107

【网络流24题】最小路径覆盖问题
【题目】1738: 最小路径覆盖问题 【题解】网络流 关于输出路径,因为即使有反向弧经过左侧点也一定会改变左侧点的去向,若没连向右侧就会被更新到0,所以不用在意。 mark记录有入度的右侧点,然后从没入度的右侧点开始把整条路径输出…

Windows的端口列表(转载)
按端口号可分为3大类: (1)公认端口(Well Known Ports):从0到1023,它们紧密绑定(binding)于一些服务。通常这些端口的通讯明确表明了某种服务的协议。例如:80端…
有了图分析,可解释的AI还远吗?
GraphAI 更多新可能随着深度学习、机器学习等人工智能技术的逐级深入,企业对挖掘大数据的关联性去探索“隐藏”在背后的商业价值提出了更高的要求。尤其是,新一代人工智能技术正从“感知智能”迈向“认知智能”,让机器实现“理解、推理、决策…

智能公交GPS
蓝斯通信推出LZ8713B*-X车载终端。这款设备是按交通部JT/T794-2011《道路运输车辆卫星定位系统车载终端技术要求 》和JT/T808-2011《道路运输车辆卫星定位系统车载终端通讯协议及数据格式》技术标准进行设计的。 产品集GPS(可选配BD2双模模块)…
数据化管理在餐饮业中的应用
一、为什么要重视数据化运营和管理? “从经营到管理,管理方向需要数据灯塔” 餐饮市场和社会各业具有相似之处,也有很明确的本质不同。 1、首先,餐饮市场不像电信、石油市场是垄断性的,餐饮市场充分透明,符…
1 元秒杀 1000+ 册爆款电子书,错过再等一年!
wow代码人们让钱包瑟瑟发抖的双十一已经来啦与此同时码不停蹄地向你奔赴而来的还有 CSDN 为你准备的???? 1 元秒杀 ????价值 3.5 万元的爆款电子书限时特惠,仅需 1 元你,准备好了吗仅限 500 人速领????????????错过悔10年系列好书一

关于XP进程问题(转载)
Smss.exe 会话管理子系统,它负责启动用户会话。这个进程是通过系统进程来初始化的,包括对已经正在运行的Winlogon,Win32(Csrss.exe)线程和设定的系统变量作出反映。在它启动这些进程后,它等待Winlogon或者C…

NoticeView
2019独角兽企业重金招聘Python工程师标准>>> NoticeView 是 iOS 的消息提醒组件,类似 TweetBot 的提醒。 转载:http://www.adobex.com/ios/source/details/00001068.htm 转载于:https://my.oschina.net/u/868244/blog/107344

elasticsearch 分片恢复经历了哪些步骤?
why 服务重启,或者与集群断网重连时,需要和集群当前的主分片的数据保持一致。 how 上图中,RecoverTarget 代表加入集群前想要同步数据的分片,RecoverSource代表当前集群中的正常分片。 同步过程本质上来说,就是通过拷贝…

Java 事件适配器 Adapter
事件适配器Adapters 在上一篇文章中: http://www.cnblogs.com/mengdd/archive/2013/02/06/2908241.html 第二个例子中,可以看到要实现相应的事件监听器接口,就必须实现其中的所有方法。 有的接口中包含多个方法(多个事件处理器&am…
Facebook面经全披露,我是怎么拿到机器学习工程师offer的?
作者 | Rahul Agarwal翻译 | Katie,责编 | 晋兆雨出品 | AI科技大本营头图 | 付费下载于视觉中国去年八月,我正在接受面试。那时,我已经分别接受Google India和Amazon India的机器学习和数据科学职位面试。然后我的上级建议我申请Facebook伦敦…

内存性能参数详解(转载)
内存性能参数详解 先说说最有效提高你机器内存性能的几个参数:CL,TRP,TRCD CAS Latency “列地址选通脉冲潜伏期” BIOS中可能的其他描述为:tCL、CAS Latency Time、CAS Timing Delay,这个值一般是1.5~3之间࿰…

一些关于Hibernate延迟加载的误区
最近面试别人,正好出的笔试题中有道关于Hibernate延迟加载的问题,聊天过程中发现很多人对Hibernate的延迟加载有些理解误区,写 些东东在这里,希望对大家有所帮助。 首先是第一个误区:延迟加载只能作用于关联实体看到这…

Java单元测试与Jutil详解(一) 简介
1.什么是单元测试 单元测试(unit testing),是指对软件中的最小可测试单元进行检查和验证。对于单元测试中单元的含义,Java里单元指一个类。总的来说,单元就是人为规定的最小的被测功能模块。单元测试是在软件开发过程中…
反转!BAT编程吸金榜来了,AI程序员刷爆了......
从2017年开始,人工智能便波澜不断,无论是从BAT高调布局AI,还是从年薪80万招聘AI应届生,炽手可热形容AI工程师一点都不过分。百度推出“少帅计划”,针对30岁以下的深度学习科学家,开出100万以上年薪!阿里巴巴…

Windows启动文件
Windows启动文件 Files Used in the Windows 2000 Boot Process FileLocationBoot stageNtldr System partition root (C:/ )Preboot and bootBoot.iniSystem partition rootBootBootsect.dosSystem partition rootBoot (optional)Ntdetect.com System partition rootBootNtboo…