Полный код файла Form3.cs

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
	
namespace WndAppAdo
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class Form3 : System.Windows.Forms.Form
	{
		private System.Data.OleDb.OleDbDataAdapter odaCustomerList;
		private System.Data.OleDb.OleDbConnection oleDbConnection1;
		private WndAppAdo.DataSet1 dsCustomerList;
		private System.Windows.Forms.ListBox lstCustomers;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.TextBox txtCustLimit;
		private System.Windows.Forms.Button btnLoadList;
		private System.Data.OleDb.OleDbDataAdapter odaCustomerIndividual;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.Label label6;
		private System.Windows.Forms.Label label7;
		private System.Windows.Forms.Label label8;
		private System.Windows.Forms.Label label9;
		private System.Windows.Forms.Label label10;
		private System.Windows.Forms.Label label11;
		private System.Windows.Forms.Label label12;
		private System.Windows.Forms.TextBox txtCustomerID;
		private System.Windows.Forms.TextBox txtCompanyName;
		private System.Windows.Forms.TextBox txtContactName;
		private System.Windows.Forms.TextBox txtContactTitle;
		private System.Windows.Forms.TextBox txtAddress;
		private System.Windows.Forms.TextBox txtCity;
		private System.Windows.Forms.TextBox txtRegion;
		private System.Windows.Forms.TextBox txtPostalCode;
		private System.Windows.Forms.TextBox txtCountry;
		private System.Windows.Forms.TextBox txtPhone;
		private System.Windows.Forms.TextBox txtFax;
		private System.Data.OleDb.OleDbCommand oleDbSelectCommand1;
		private System.Data.OleDb.OleDbCommand oleDbSelectCommand2;
		private WndAppAdo.dsCustomerIndividual dsCustomerIndividual;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;
	
		public Form3()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();
	
			//
			// TODO: Add any constructor code after InitializeComponent call
			//
//			odaCustomerList.Fill(dsCustomerList);
		}
	
		/// <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.odaCustomerList = new System.Data.OleDb.OleDbDataAdapter();
			this.oleDbSelectCommand1 = new System.Data.OleDb.OleDbCommand();
			this.oleDbConnection1 = new System.Data.OleDb.OleDbConnection();
			this.dsCustomerList = new WndAppAdo.DataSet1();
			this.lstCustomers = new System.Windows.Forms.ListBox();
			this.label1 = new System.Windows.Forms.Label();
			this.txtCustLimit = new System.Windows.Forms.TextBox();
			this.btnLoadList = new System.Windows.Forms.Button();
			this.odaCustomerIndividual = new System.Data.OleDb.OleDbDataAdapter();
			this.oleDbSelectCommand2 = new System.Data.OleDb.OleDbCommand();
			this.txtCustomerID = new System.Windows.Forms.TextBox();
			this.label2 = new System.Windows.Forms.Label();
			this.label3 = new System.Windows.Forms.Label();
			this.label4 = new System.Windows.Forms.Label();
			this.label5 = new System.Windows.Forms.Label();
			this.label6 = new System.Windows.Forms.Label();
			this.label7 = new System.Windows.Forms.Label();
			this.label8 = new System.Windows.Forms.Label();
			this.label9 = new System.Windows.Forms.Label();
			this.label10 = new System.Windows.Forms.Label();
			this.label11 = new System.Windows.Forms.Label();
			this.label12 = new System.Windows.Forms.Label();
			this.txtCompanyName = new System.Windows.Forms.TextBox();
			this.txtContactName = new System.Windows.Forms.TextBox();
			this.txtContactTitle = new System.Windows.Forms.TextBox();
			this.txtAddress = new System.Windows.Forms.TextBox();
			this.txtCity = new System.Windows.Forms.TextBox();
			this.txtRegion = new System.Windows.Forms.TextBox();
			this.txtPostalCode = new System.Windows.Forms.TextBox();
			this.txtCountry = new System.Windows.Forms.TextBox();
			this.txtPhone = new System.Windows.Forms.TextBox();
			this.txtFax = new System.Windows.Forms.TextBox();
			this.dsCustomerIndividual = new WndAppAdo.dsCustomerIndividual();
			((System.ComponentModel.ISupportInitialize)(this.dsCustomerList)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.dsCustomerIndividual)).BeginInit();
			this.SuspendLayout();
			// 
			// odaCustomerList
			// 
			this.odaCustomerList.SelectCommand = this.oleDbSelectCommand1;
			this.odaCustomerList.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")})});
			// 
			// oleDbSelectCommand1
			// 
			this.oleDbSelectCommand1.CommandText = "SELECT CustomerID, CompanyName FROM Customers WHERE (CompanyName LIKE ? + \'%\')";
			this.oleDbSelectCommand1.Connection = this.oleDbConnection1;
			this.oleDbSelectCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("CompanyName", System.Data.OleDb.OleDbType.VarWChar, 40, "CompanyName"));
			// 
			// oleDbConnection1
			// 
			this.oleDbConnection1.ConnectionString = @"Integrated Security=SSPI;Packet Size=4096;Data Source=localhost;Tag with column collation when possible=False;Initial Catalog=Northwind;Use Procedure for Prepare=1;Auto Translate=True;Persist Security Info=False;Provider=""SQLOLEDB.1"";Workstation ID=3873CB87DA2448E;Use Encryption for Data=False";
			// 
			// dsCustomerList
			// 
			this.dsCustomerList.DataSetName = "DataSet1";
			this.dsCustomerList.Locale = new System.Globalization.CultureInfo("ru-RU");
			// 
			// lstCustomers
			// 
			this.lstCustomers.DataSource = this.dsCustomerList;
			this.lstCustomers.DisplayMember = "Customers.CompanyName";
			this.lstCustomers.Location = new System.Drawing.Point(8, 35);
			this.lstCustomers.Name = "lstCustomers";
			this.lstCustomers.Size = new System.Drawing.Size(280, 264);
			this.lstCustomers.TabIndex = 0;
			this.lstCustomers.ValueMember = "Customers.CustomerID";
			this.lstCustomers.SelectedIndexChanged += new System.EventHandler(this.lstCustomers_SelectedIndexChanged);
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(8, 8);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(48, 20);
			this.label1.TabIndex = 1;
			this.label1.Text = "Клиент:";
			this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// txtCustLimit
			// 
			this.txtCustLimit.Location = new System.Drawing.Point(56, 8);
			this.txtCustLimit.Name = "txtCustLimit";
			this.txtCustLimit.Size = new System.Drawing.Size(152, 20);
			this.txtCustLimit.TabIndex = 2;
			this.txtCustLimit.Text = "";
			// 
			// btnLoadList
			// 
			this.btnLoadList.Location = new System.Drawing.Point(213, 8);
			this.btnLoadList.Name = "btnLoadList";
			this.btnLoadList.TabIndex = 3;
			this.btnLoadList.Text = "Заполнить";
			this.btnLoadList.Click += new System.EventHandler(this.btnLoadList_Click);
			// 
			// odaCustomerIndividual
			// 
			this.odaCustomerIndividual.SelectCommand = this.oleDbSelectCommand2;
			this.odaCustomerIndividual.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")})});
			// 
			// oleDbSelectCommand2
			// 
			this.oleDbSelectCommand2.CommandText = "SELECT CustomerID, CompanyName, ContactName, ContactTitle, Address, City, Region," +
				" PostalCode, Country, Phone, Fax FROM Customers WHERE (CustomerID = ?)";
			this.oleDbSelectCommand2.Connection = this.oleDbConnection1;
			this.oleDbSelectCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("CustomerID", System.Data.OleDb.OleDbType.VarWChar, 5, "CustomerID"));
			// 
			// txtCustomerID
			// 
			this.txtCustomerID.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.txtCustomerID.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.dsCustomerIndividual, "Customers.CustomerID"));
			this.txtCustomerID.Location = new System.Drawing.Point(392, 40);
			this.txtCustomerID.Name = "txtCustomerID";
			this.txtCustomerID.ReadOnly = true;
			this.txtCustomerID.TabIndex = 4;
			this.txtCustomerID.Text = "";
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(296, 40);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(96, 20);
			this.label2.TabIndex = 5;
			this.label2.Text = "Customer ID:";
			this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(296, 64);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(96, 20);
			this.label3.TabIndex = 6;
			this.label3.Text = "Company Name:";
			this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// label4
			// 
			this.label4.Location = new System.Drawing.Point(296, 88);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(96, 20);
			this.label4.TabIndex = 7;
			this.label4.Text = "Contact Name:";
			this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// label5
			// 
			this.label5.Location = new System.Drawing.Point(296, 112);
			this.label5.Name = "label5";
			this.label5.Size = new System.Drawing.Size(96, 20);
			this.label5.TabIndex = 8;
			this.label5.Text = "Contact Title:";
			this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// label6
			// 
			this.label6.Location = new System.Drawing.Point(296, 136);
			this.label6.Name = "label6";
			this.label6.Size = new System.Drawing.Size(96, 20);
			this.label6.TabIndex = 9;
			this.label6.Text = "Address:";
			this.label6.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// label7
			// 
			this.label7.Location = new System.Drawing.Point(296, 160);
			this.label7.Name = "label7";
			this.label7.Size = new System.Drawing.Size(96, 20);
			this.label7.TabIndex = 10;
			this.label7.Text = "City:";
			this.label7.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// label8
			// 
			this.label8.Location = new System.Drawing.Point(296, 184);
			this.label8.Name = "label8";
			this.label8.Size = new System.Drawing.Size(96, 20);
			this.label8.TabIndex = 11;
			this.label8.Text = "Region:";
			this.label8.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// label9
			// 
			this.label9.Location = new System.Drawing.Point(296, 208);
			this.label9.Name = "label9";
			this.label9.Size = new System.Drawing.Size(96, 20);
			this.label9.TabIndex = 12;
			this.label9.Text = "Postal Code:";
			this.label9.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// label10
			// 
			this.label10.Location = new System.Drawing.Point(296, 232);
			this.label10.Name = "label10";
			this.label10.Size = new System.Drawing.Size(96, 20);
			this.label10.TabIndex = 13;
			this.label10.Text = "Country:";
			this.label10.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// label11
			// 
			this.label11.Location = new System.Drawing.Point(296, 256);
			this.label11.Name = "label11";
			this.label11.Size = new System.Drawing.Size(96, 20);
			this.label11.TabIndex = 14;
			this.label11.Text = "Phone:";
			this.label11.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// label12
			// 
			this.label12.Location = new System.Drawing.Point(296, 280);
			this.label12.Name = "label12";
			this.label12.Size = new System.Drawing.Size(96, 20);
			this.label12.TabIndex = 15;
			this.label12.Text = "Fax:";
			this.label12.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// txtCompanyName
			// 
			this.txtCompanyName.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.txtCompanyName.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.dsCustomerIndividual, "Customers.CompanyName"));
			this.txtCompanyName.Location = new System.Drawing.Point(392, 64);
			this.txtCompanyName.Name = "txtCompanyName";
			this.txtCompanyName.ReadOnly = true;
			this.txtCompanyName.TabIndex = 16;
			this.txtCompanyName.Text = "";
			// 
			// txtContactName
			// 
			this.txtContactName.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.txtContactName.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.dsCustomerIndividual, "Customers.ContactName"));
			this.txtContactName.Location = new System.Drawing.Point(392, 88);
			this.txtContactName.Name = "txtContactName";
			this.txtContactName.ReadOnly = true;
			this.txtContactName.TabIndex = 17;
			this.txtContactName.Text = "";
			// 
			// txtContactTitle
			// 
			this.txtContactTitle.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.txtContactTitle.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.dsCustomerIndividual, "Customers.ContactTitle"));
			this.txtContactTitle.Location = new System.Drawing.Point(392, 112);
			this.txtContactTitle.Name = "txtContactTitle";
			this.txtContactTitle.ReadOnly = true;
			this.txtContactTitle.TabIndex = 18;
			this.txtContactTitle.Text = "";
			// 
			// txtAddress
			// 
			this.txtAddress.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.txtAddress.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.dsCustomerIndividual, "Customers.Address"));
			this.txtAddress.Location = new System.Drawing.Point(392, 136);
			this.txtAddress.Name = "txtAddress";
			this.txtAddress.ReadOnly = true;
			this.txtAddress.TabIndex = 19;
			this.txtAddress.Text = "";
			// 
			// txtCity
			// 
			this.txtCity.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.txtCity.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.dsCustomerIndividual, "Customers.City"));
	
			this.txtCity.Location = new System.Drawing.Point(392, 160);
			this.txtCity.Name = "txtCity";
			this.txtCity.ReadOnly = true;
			this.txtCity.TabIndex = 20;
			this.txtCity.Text = "";
			// 
			// txtRegion
			// 
			this.txtRegion.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.txtRegion.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.dsCustomerIndividual, "Customers.Region"));
			this.txtRegion.Location = new System.Drawing.Point(392, 184);
			this.txtRegion.Name = "txtRegion";
			this.txtRegion.ReadOnly = true;
			this.txtRegion.TabIndex = 21;
			this.txtRegion.Text = "";
			// 
			// txtPostalCode
			// 
			this.txtPostalCode.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.txtPostalCode.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.dsCustomerIndividual, "Customers.PostalCode"));
			this.txtPostalCode.Location = new System.Drawing.Point(392, 208);
			this.txtPostalCode.Name = "txtPostalCode";
			this.txtPostalCode.ReadOnly = true;
			this.txtPostalCode.TabIndex = 22;
			this.txtPostalCode.Text = "";
			// 
			// txtCountry
			// 
			this.txtCountry.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.txtCountry.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.dsCustomerIndividual, "Customers.Country"));
			this.txtCountry.Location = new System.Drawing.Point(392, 232);
			this.txtCountry.Name = "txtCountry";
			this.txtCountry.ReadOnly = true;
			this.txtCountry.TabIndex = 23;
			this.txtCountry.Text = "";
			// 
			// txtPhone
			// 
			this.txtPhone.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.txtPhone.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.dsCustomerIndividual, "Customers.Phone"));
			this.txtPhone.Location = new System.Drawing.Point(392, 256);
			this.txtPhone.Name = "txtPhone";
			this.txtPhone.ReadOnly = true;
			this.txtPhone.TabIndex = 24;
			this.txtPhone.Text = "";
			// 
			// txtFax
			// 
			this.txtFax.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.txtFax.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.dsCustomerIndividual, "Customers.Fax"));
			this.txtFax.Location = new System.Drawing.Point(392, 280);
			this.txtFax.Name = "txtFax";
			this.txtFax.ReadOnly = true;
			this.txtFax.TabIndex = 25;
			this.txtFax.Text = "";
			// 
			// dsCustomerIndividual
			// 
			this.dsCustomerIndividual.DataSetName = "dsCustomerIndividual";
			this.dsCustomerIndividual.Locale = new System.Globalization.CultureInfo("ru-RU");
			// 
			// Form3
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(504, 309);
			this.Controls.Add(this.txtFax);
			this.Controls.Add(this.txtPhone);
			this.Controls.Add(this.txtCountry);
			this.Controls.Add(this.txtPostalCode);
			this.Controls.Add(this.txtRegion);
			this.Controls.Add(this.txtCity);
			this.Controls.Add(this.txtAddress);
			this.Controls.Add(this.txtContactTitle);
			this.Controls.Add(this.txtContactName);
			this.Controls.Add(this.txtCompanyName);
			this.Controls.Add(this.label12);
			this.Controls.Add(this.label11);
			this.Controls.Add(this.label10);
			this.Controls.Add(this.label9);
			this.Controls.Add(this.label8);
			this.Controls.Add(this.label7);
			this.Controls.Add(this.label6);
			this.Controls.Add(this.label5);
			this.Controls.Add(this.label4);
			this.Controls.Add(this.label3);
			this.Controls.Add(this.label2);
			this.Controls.Add(this.txtCustomerID);
			this.Controls.Add(this.btnLoadList);
			this.Controls.Add(this.txtCustLimit);
			this.Controls.Add(this.label1);
			this.Controls.Add(this.lstCustomers);
			this.Name = "Form3";
			this.Text = "Form3";
			((System.ComponentModel.ISupportInitialize)(this.dsCustomerList)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.dsCustomerIndividual)).EndInit();
			this.ResumeLayout(false);
	
		}
		#endregion

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new Form3());
		}
	
		// Обработчик кнопки
		private void btnLoadList_Click(object sender, System.EventArgs e)
		{
			// Присвоить параметру адаптера данных значение,
			// введенное для ограничения объема списка
			odaCustomerList.SelectCommand.Parameters[0].Value
				              = txtCustLimit.Text;
			// Удалить текущие данные в наборе данных
			dsCustomerList.Clear();
			// Заполнить набор данных списком заказчиков
			odaCustomerList.Fill(dsCustomerList);
			// Заполнить отдельный набор данных для начальной записи
			RefreshIndividual();
		}
	
		// Обновление отдельного набора данных
		private void RefreshIndividual()
		{
			// Очистить отдельный набор данных
			dsCustomerIndividual.Clear();
			// Определить, выбран ли текущий элемент
			if(lstCustomers.SelectedIndex != -1)
			{
				// Присвоить параметру SQL адаптера данных отдельного
				// набора выбранный идентификатор заказчика
				// Заполнить набор данных
				try
				{
					odaCustomerIndividual.SelectCommand.Parameters[0].Value
										= lstCustomers.SelectedValue;
					odaCustomerIndividual.Fill(dsCustomerIndividual);
				}
				catch(Exception e1)
				{
					MessageBox.Show(e1.Message);
				}
			}
		}
	
		// Обработчик выбора элемента списка
		private void lstCustomers_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			// Заполнить отдельный набор данных значениями
			// полей текущего элемента списка
			RefreshIndividual();
		}
	}
}