⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.cs

📁 Professional C# 2nd Edition
💻 CS
📖 第 1 页 / 共 2 页
字号:
			// 
			this.supplierDelete.CommandText = @"DELETE FROM Suppliers WHERE (SupplierID = @Original_SupplierID) 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.supplierDelete.Connection = this.sqlConnection;
			this.supplierDelete.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_SupplierID", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "SupplierID", System.Data.DataRowVersion.Original, null));
			this.supplierDelete.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.supplierDelete.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.supplierDelete.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.supplierDelete.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.supplierDelete.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.supplierDelete.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.supplierDelete.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.supplierDelete.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.supplierDelete.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.supplierDelete.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));
			// 
			// supplierDataAdapter
			// 
			this.supplierDataAdapter.DeleteCommand = this.supplierDelete;
			this.supplierDataAdapter.InsertCommand = this.supplierInsert;
			this.supplierDataAdapter.SelectCommand = this.supplierSelect;
			this.supplierDataAdapter.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
																										  new System.Data.Common.DataTableMapping("Table", "Suppliers", new System.Data.Common.DataColumnMapping[] {
																																																					   new System.Data.Common.DataColumnMapping("SupplierID", "SupplierID"),
																																																					   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"),
																																																					   new System.Data.Common.DataColumnMapping("HomePage", "HomePage")})});
			this.supplierDataAdapter.UpdateCommand = this.supplierUpdate;
			// 
			// supplierDataSet
			// 
			this.supplierDataSet.DataSetName = "SupplierDataSet";
			this.supplierDataSet.Locale = new System.Globalization.CultureInfo("en-GB");
			this.supplierDataSet.Namespace = "http://www.tempuri.org/DataSet1.xsd";
			// 
			// dataGrid1
			// 
			this.dataGrid1.Anchor = (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
				| System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right);
			this.dataGrid1.DataMember = "";
			this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
			this.dataGrid1.Location = new System.Drawing.Point(8, 8);
			this.dataGrid1.Name = "dataGrid1";
			this.dataGrid1.Size = new System.Drawing.Size(416, 336);
			this.dataGrid1.TabIndex = 0;
			// 
			// retrieveButton
			// 
			this.retrieveButton.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right);
			this.retrieveButton.Location = new System.Drawing.Point(248, 352);
			this.retrieveButton.Name = "retrieveButton";
			this.retrieveButton.Size = new System.Drawing.Size(80, 23);
			this.retrieveButton.TabIndex = 1;
			this.retrieveButton.Text = "&Retrieve";
			this.retrieveButton.Click += new System.EventHandler(this.retrieveButton_Click);
			// 
			// updateButton
			// 
			this.updateButton.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right);
			this.updateButton.Location = new System.Drawing.Point(344, 352);
			this.updateButton.Name = "updateButton";
			this.updateButton.Size = new System.Drawing.Size(80, 23);
			this.updateButton.TabIndex = 2;
			this.updateButton.Text = "&Update";
			this.updateButton.Click += new System.EventHandler(this.updateButton_Click);
			// 
			// datasetUpdate
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(432, 379);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.updateButton,
																		  this.retrieveButton,
																		  this.dataGrid1});
			this.Name = "datasetUpdate";
			this.Text = "10_UpdatingData";
			((System.ComponentModel.ISupportInitialize)(this.supplierDataSet)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new datasetUpdate());
		}

		/// <summary>
		/// This method is called to retrieve data from the database, and populate the data grid
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void retrieveButton_Click(object sender, System.EventArgs e)
		{
			// Fill the data adapter from the database
			supplierDataAdapter.Fill ( supplierDataSet , "Supplier" ) ;

			// And display the data in the data grid...
			dataGrid1.SetDataBinding ( supplierDataSet , "Supplier" ) ;

			// And disable the retrieve button...
			retrieveButton.Enabled = false ;
		}

		/// <summary>
		/// Called when the user clicks the Update button - persist all changes to the database
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void updateButton_Click(object sender, System.EventArgs e)
		{
			// Update the database
			int modified = supplierDataAdapter.Update ( supplierDataSet , "Supplier" ) ;

			if ( modified > 0 )
				MessageBox.Show ( string.Format ( "Modified {0} rows" , modified ) ) ;
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -