Form1.cs
Upload User: chinafred
Upload Date: 2007-08-14
Package Size: 10127k
Code Size: 30k
Category:

ADO-ODBC

Development Platform:

C#

  1. using System;
  2. using System.Drawing;
  3. using System.Collections;
  4. using System.ComponentModel;
  5. using System.Windows.Forms;
  6. using System.Data;
  7. using System.Data.SqlClient;
  8. namespace ch6_2
  9. {
  10. /// <summary>
  11. /// Form1 的摘要说明。
  12. /// </summary>
  13. public class Form1 : System.Windows.Forms.Form
  14. {
  15. private System.Windows.Forms.Label label1;
  16. private System.Windows.Forms.ComboBox comboBox1;
  17. private System.Data.DataSet dataSet1;
  18. private System.Windows.Forms.GroupBox groupBox1;
  19. private System.Windows.Forms.Label label2;
  20. private System.Windows.Forms.Label label3;
  21. private System.Windows.Forms.Label label4;
  22. private System.Windows.Forms.Label label5;
  23. private System.Windows.Forms.Label label6;
  24. private System.Windows.Forms.Label label7;
  25. private System.Windows.Forms.Label label8;
  26. private System.Windows.Forms.Label label9;
  27. private System.Windows.Forms.Label label10;
  28. private System.Windows.Forms.Label label11;
  29. private System.Windows.Forms.Label label12;
  30. private System.Windows.Forms.TextBox textBox1;
  31. private System.Windows.Forms.TextBox textBox2;
  32. private System.Windows.Forms.TextBox textBox3;
  33. private System.Windows.Forms.TextBox textBox4;
  34. private System.Windows.Forms.TextBox textBox5;
  35. private System.Windows.Forms.TextBox textBox6;
  36. private System.Windows.Forms.TextBox textBox7;
  37. private System.Windows.Forms.TextBox textBox8;
  38. private System.Windows.Forms.TextBox textBox9;
  39. private System.Windows.Forms.TextBox textBox10;
  40. private System.Windows.Forms.TextBox textBox11;
  41. private System.Data.SqlClient.SqlConnection sqlConnection1;
  42. private System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
  43. private System.Data.SqlClient.SqlCommand sqlSelectCommand1;
  44. private System.Data.SqlClient.SqlCommand sqlInsertCommand1;
  45. private System.Data.SqlClient.SqlCommand sqlUpdateCommand1;
  46. private System.Data.SqlClient.SqlCommand sqlDeleteCommand1;
  47. /// <summary>
  48. /// 必需的设计器变量。
  49. /// </summary>
  50. private System.ComponentModel.Container components = null;
  51. public Form1()
  52. {
  53. //
  54. // Windows 窗体设计器支持所必需的
  55. //
  56. InitializeComponent();
  57. InitialComboBox();
  58. //
  59. // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
  60. //
  61. }
  62. private void InitialComboBox()
  63. {
  64.     //填充数据集
  65. this.sqlDataAdapter1.Fill(this.dataSet1,"Customers");
  66. //设置comboBox的绑定属性
  67. this.comboBox1.DataSource=this.dataSet1;
  68. this.comboBox1.DisplayMember="Customers.ContactName";
  69. this.comboBox1.ValueMember="Customers.ContactName";
  70. }
  71. /// <summary>
  72. /// 清理所有正在使用的资源。
  73. /// </summary>
  74. protected override void Dispose( bool disposing )
  75. {
  76. if( disposing )
  77. {
  78. if (components != null) 
  79. {
  80. components.Dispose();
  81. }
  82. }
  83. base.Dispose( disposing );
  84. }
  85. #region Windows Form Designer generated code
  86. /// <summary>
  87. /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  88. /// 此方法的内容。
  89. /// </summary>
  90. private void InitializeComponent()
  91. {
  92. this.label1 = new System.Windows.Forms.Label();
  93. this.comboBox1 = new System.Windows.Forms.ComboBox();
  94. this.dataSet1 = new System.Data.DataSet();
  95. this.groupBox1 = new System.Windows.Forms.GroupBox();
  96. this.label2 = new System.Windows.Forms.Label();
  97. this.label3 = new System.Windows.Forms.Label();
  98. this.label4 = new System.Windows.Forms.Label();
  99. this.label5 = new System.Windows.Forms.Label();
  100. this.label6 = new System.Windows.Forms.Label();
  101. this.label7 = new System.Windows.Forms.Label();
  102. this.label8 = new System.Windows.Forms.Label();
  103. this.label9 = new System.Windows.Forms.Label();
  104. this.label10 = new System.Windows.Forms.Label();
  105. this.label11 = new System.Windows.Forms.Label();
  106. this.label12 = new System.Windows.Forms.Label();
  107. this.textBox1 = new System.Windows.Forms.TextBox();
  108. this.textBox2 = new System.Windows.Forms.TextBox();
  109. this.textBox3 = new System.Windows.Forms.TextBox();
  110. this.textBox4 = new System.Windows.Forms.TextBox();
  111. this.textBox5 = new System.Windows.Forms.TextBox();
  112. this.textBox6 = new System.Windows.Forms.TextBox();
  113. this.textBox7 = new System.Windows.Forms.TextBox();
  114. this.textBox8 = new System.Windows.Forms.TextBox();
  115. this.textBox9 = new System.Windows.Forms.TextBox();
  116. this.textBox10 = new System.Windows.Forms.TextBox();
  117. this.textBox11 = new System.Windows.Forms.TextBox();
  118. this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
  119. this.sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter();
  120. this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
  121. this.sqlInsertCommand1 = new System.Data.SqlClient.SqlCommand();
  122. this.sqlUpdateCommand1 = new System.Data.SqlClient.SqlCommand();
  123. this.sqlDeleteCommand1 = new System.Data.SqlClient.SqlCommand();
  124. ((System.ComponentModel.ISupportInitialize)(this.dataSet1)).BeginInit();
  125. this.groupBox1.SuspendLayout();
  126. this.SuspendLayout();
  127. // 
  128. // label1
  129. // 
  130. this.label1.Location = new System.Drawing.Point(32, 16);
  131. this.label1.Name = "label1";
  132. this.label1.Size = new System.Drawing.Size(96, 16);
  133. this.label1.TabIndex = 1;
  134. this.label1.Text = "选择顾客名字";
  135. // 
  136. // comboBox1
  137. // 
  138. this.comboBox1.Location = new System.Drawing.Point(152, 16);
  139. this.comboBox1.Name = "comboBox1";
  140. this.comboBox1.Size = new System.Drawing.Size(136, 20);
  141. this.comboBox1.TabIndex = 2;
  142. this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);
  143. // 
  144. // dataSet1
  145. // 
  146. this.dataSet1.DataSetName = "NewDataSet";
  147. this.dataSet1.Locale = new System.Globalization.CultureInfo("zh-CN");
  148. // 
  149. // groupBox1
  150. // 
  151. this.groupBox1.Controls.AddRange(new System.Windows.Forms.Control[] {
  152. this.textBox11,
  153. this.textBox10,
  154. this.textBox9,
  155. this.textBox8,
  156. this.textBox7,
  157. this.textBox6,
  158. this.textBox5,
  159. this.textBox4,
  160. this.textBox3,
  161. this.textBox2,
  162. this.textBox1,
  163. this.label12,
  164. this.label11,
  165. this.label10,
  166. this.label9,
  167. this.label8,
  168. this.label7,
  169. this.label6,
  170. this.label5,
  171. this.label4,
  172. this.label3,
  173. this.label2});
  174. this.groupBox1.Location = new System.Drawing.Point(24, 48);
  175. this.groupBox1.Name = "groupBox1";
  176. this.groupBox1.Size = new System.Drawing.Size(280, 296);
  177. this.groupBox1.TabIndex = 3;
  178. this.groupBox1.TabStop = false;
  179. this.groupBox1.Text = "顾客详细信息";
  180. // 
  181. // label2
  182. // 
  183. this.label2.Location = new System.Drawing.Point(16, 24);
  184. this.label2.Name = "label2";
  185. this.label2.Size = new System.Drawing.Size(88, 18);
  186. this.label2.TabIndex = 0;
  187. this.label2.Text = "CustomerID";
  188. // 
  189. // label3
  190. // 
  191. this.label3.Location = new System.Drawing.Point(16, 48);
  192. this.label3.Name = "label3";
  193. this.label3.Size = new System.Drawing.Size(88, 18);
  194. this.label3.TabIndex = 1;
  195. this.label3.Text = "CompanyName";
  196. // 
  197. // label4
  198. // 
  199. this.label4.Location = new System.Drawing.Point(16, 72);
  200. this.label4.Name = "label4";
  201. this.label4.Size = new System.Drawing.Size(88, 18);
  202. this.label4.TabIndex = 2;
  203. this.label4.Text = "ContactName";
  204. // 
  205. // label5
  206. // 
  207. this.label5.Location = new System.Drawing.Point(16, 96);
  208. this.label5.Name = "label5";
  209. this.label5.Size = new System.Drawing.Size(88, 18);
  210. this.label5.TabIndex = 3;
  211. this.label5.Text = "ContactTitle";
  212. // 
  213. // label6
  214. // 
  215. this.label6.Location = new System.Drawing.Point(16, 120);
  216. this.label6.Name = "label6";
  217. this.label6.Size = new System.Drawing.Size(88, 18);
  218. this.label6.TabIndex = 4;
  219. this.label6.Text = "Address";
  220. // 
  221. // label7
  222. // 
  223. this.label7.Location = new System.Drawing.Point(16, 144);
  224. this.label7.Name = "label7";
  225. this.label7.Size = new System.Drawing.Size(88, 18);
  226. this.label7.TabIndex = 5;
  227. this.label7.Text = "City";
  228. // 
  229. // label8
  230. // 
  231. this.label8.Location = new System.Drawing.Point(16, 168);
  232. this.label8.Name = "label8";
  233. this.label8.Size = new System.Drawing.Size(88, 18);
  234. this.label8.TabIndex = 6;
  235. this.label8.Text = "Region";
  236. // 
  237. // label9
  238. // 
  239. this.label9.Location = new System.Drawing.Point(16, 192);
  240. this.label9.Name = "label9";
  241. this.label9.Size = new System.Drawing.Size(88, 18);
  242. this.label9.TabIndex = 7;
  243. this.label9.Text = "PostalCode";
  244. // 
  245. // label10
  246. // 
  247. this.label10.Location = new System.Drawing.Point(16, 216);
  248. this.label10.Name = "label10";
  249. this.label10.Size = new System.Drawing.Size(88, 18);
  250. this.label10.TabIndex = 8;
  251. this.label10.Text = "Country";
  252. // 
  253. // label11
  254. // 
  255. this.label11.Location = new System.Drawing.Point(16, 240);
  256. this.label11.Name = "label11";
  257. this.label11.Size = new System.Drawing.Size(88, 18);
  258. this.label11.TabIndex = 9;
  259. this.label11.Text = "Phone";
  260. // 
  261. // label12
  262. // 
  263. this.label12.Location = new System.Drawing.Point(16, 264);
  264. this.label12.Name = "label12";
  265. this.label12.Size = new System.Drawing.Size(88, 18);
  266. this.label12.TabIndex = 10;
  267. this.label12.Text = "Fax";
  268. // 
  269. // textBox1
  270. // 
  271. this.textBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
  272. this.textBox1.Location = new System.Drawing.Point(128, 24);
  273. this.textBox1.Name = "textBox1";
  274. this.textBox1.Size = new System.Drawing.Size(136, 21);
  275. this.textBox1.TabIndex = 11;
  276. this.textBox1.Text = "";
  277. // 
  278. // textBox2
  279. // 
  280. this.textBox2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
  281. this.textBox2.Location = new System.Drawing.Point(128, 48);
  282. this.textBox2.Name = "textBox2";
  283. this.textBox2.Size = new System.Drawing.Size(136, 21);
  284. this.textBox2.TabIndex = 12;
  285. this.textBox2.Text = "";
  286. // 
  287. // textBox3
  288. // 
  289. this.textBox3.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
  290. this.textBox3.Location = new System.Drawing.Point(128, 72);
  291. this.textBox3.Name = "textBox3";
  292. this.textBox3.Size = new System.Drawing.Size(136, 21);
  293. this.textBox3.TabIndex = 13;
  294. this.textBox3.Text = "";
  295. // 
  296. // textBox4
  297. // 
  298. this.textBox4.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
  299. this.textBox4.Location = new System.Drawing.Point(128, 96);
  300. this.textBox4.Name = "textBox4";
  301. this.textBox4.Size = new System.Drawing.Size(136, 21);
  302. this.textBox4.TabIndex = 14;
  303. this.textBox4.Text = "";
  304. // 
  305. // textBox5
  306. // 
  307. this.textBox5.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
  308. this.textBox5.Location = new System.Drawing.Point(128, 120);
  309. this.textBox5.Name = "textBox5";
  310. this.textBox5.Size = new System.Drawing.Size(136, 21);
  311. this.textBox5.TabIndex = 15;
  312. this.textBox5.Text = "";
  313. // 
  314. // textBox6
  315. // 
  316. this.textBox6.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
  317. this.textBox6.Location = new System.Drawing.Point(128, 144);
  318. this.textBox6.Name = "textBox6";
  319. this.textBox6.Size = new System.Drawing.Size(136, 21);
  320. this.textBox6.TabIndex = 16;
  321. this.textBox6.Text = "";
  322. // 
  323. // textBox7
  324. // 
  325. this.textBox7.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
  326. this.textBox7.Location = new System.Drawing.Point(128, 168);
  327. this.textBox7.Name = "textBox7";
  328. this.textBox7.Size = new System.Drawing.Size(136, 21);
  329. this.textBox7.TabIndex = 17;
  330. this.textBox7.Text = "";
  331. // 
  332. // textBox8
  333. // 
  334. this.textBox8.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
  335. this.textBox8.Location = new System.Drawing.Point(128, 192);
  336. this.textBox8.Name = "textBox8";
  337. this.textBox8.Size = new System.Drawing.Size(136, 21);
  338. this.textBox8.TabIndex = 18;
  339. this.textBox8.Text = "";
  340. // 
  341. // textBox9
  342. // 
  343. this.textBox9.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
  344. this.textBox9.Location = new System.Drawing.Point(128, 216);
  345. this.textBox9.Name = "textBox9";
  346. this.textBox9.Size = new System.Drawing.Size(136, 21);
  347. this.textBox9.TabIndex = 19;
  348. this.textBox9.Text = "";
  349. // 
  350. // textBox10
  351. // 
  352. this.textBox10.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
  353. this.textBox10.Location = new System.Drawing.Point(128, 240);
  354. this.textBox10.Name = "textBox10";
  355. this.textBox10.Size = new System.Drawing.Size(136, 21);
  356. this.textBox10.TabIndex = 20;
  357. this.textBox10.Text = "";
  358. // 
  359. // textBox11
  360. // 
  361. this.textBox11.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
  362. this.textBox11.Location = new System.Drawing.Point(128, 264);
  363. this.textBox11.Name = "textBox11";
  364. this.textBox11.Size = new System.Drawing.Size(136, 21);
  365. this.textBox11.TabIndex = 21;
  366. this.textBox11.Text = "";
  367. // 
  368. // sqlConnection1
  369. // 
  370. this.sqlConnection1.ConnectionString = "data source=TRINCE-JULIE\NetSDK;initial catalog=Northwind;integrated security=SSP" +
  371. "I;persist security info=False;workstation id=TRINCE-JULIE;packet size=4096";
  372. // 
  373. // sqlDataAdapter1
  374. // 
  375. this.sqlDataAdapter1.DeleteCommand = this.sqlDeleteCommand1;
  376. this.sqlDataAdapter1.InsertCommand = this.sqlInsertCommand1;
  377. this.sqlDataAdapter1.SelectCommand = this.sqlSelectCommand1;
  378. this.sqlDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
  379.   new System.Data.Common.DataTableMapping("Table", "Customers", new System.Data.Common.DataColumnMapping[] {
  380.    new System.Data.Common.DataColumnMapping("CustomerID", "CustomerID"),
  381.    new System.Data.Common.DataColumnMapping("CompanyName", "CompanyName"),
  382.    new System.Data.Common.DataColumnMapping("ContactName", "ContactName"),
  383.    new System.Data.Common.DataColumnMapping("ContactTitle", "ContactTitle"),
  384.    new System.Data.Common.DataColumnMapping("Address", "Address"),
  385.    new System.Data.Common.DataColumnMapping("City", "City"),
  386.    new System.Data.Common.DataColumnMapping("Region", "Region"),
  387.    new System.Data.Common.DataColumnMapping("PostalCode", "PostalCode"),
  388.    new System.Data.Common.DataColumnMapping("Country", "Country"),
  389.    new System.Data.Common.DataColumnMapping("Phone", "Phone"),
  390.    new System.Data.Common.DataColumnMapping("Fax", "Fax")})});
  391. this.sqlDataAdapter1.UpdateCommand = this.sqlUpdateCommand1;
  392. // 
  393. // sqlSelectCommand1
  394. // 
  395. this.sqlSelectCommand1.CommandText = "SELECT CustomerID, CompanyName, ContactName, ContactTitle, Address, City, Region," +
  396. " PostalCode, Country, Phone, Fax FROM Customers";
  397. this.sqlSelectCommand1.Connection = this.sqlConnection1;
  398. // 
  399. // sqlInsertCommand1
  400. // 
  401. 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)";
  402. this.sqlInsertCommand1.Connection = this.sqlConnection1;
  403. this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@CustomerID", System.Data.SqlDbType.NVarChar, 5, "CustomerID"));
  404. this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@CompanyName", System.Data.SqlDbType.NVarChar, 40, "CompanyName"));
  405. this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ContactName", System.Data.SqlDbType.NVarChar, 30, "ContactName"));
  406. this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ContactTitle", System.Data.SqlDbType.NVarChar, 30, "ContactTitle"));
  407. this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Address", System.Data.SqlDbType.NVarChar, 60, "Address"));
  408. this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@City", System.Data.SqlDbType.NVarChar, 15, "City"));
  409. this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Region", System.Data.SqlDbType.NVarChar, 15, "Region"));
  410. this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@PostalCode", System.Data.SqlDbType.NVarChar, 10, "PostalCode"));
  411. this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Country", System.Data.SqlDbType.NVarChar, 15, "Country"));
  412. this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Phone", System.Data.SqlDbType.NVarChar, 24, "Phone"));
  413. this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Fax", System.Data.SqlDbType.NVarChar, 24, "Fax"));
  414. // 
  415. // sqlUpdateCommand1
  416. // 
  417. 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)";
  418. this.sqlUpdateCommand1.Connection = this.sqlConnection1;
  419. this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@CustomerID", System.Data.SqlDbType.NVarChar, 5, "CustomerID"));
  420. this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@CompanyName", System.Data.SqlDbType.NVarChar, 40, "CompanyName"));
  421. this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ContactName", System.Data.SqlDbType.NVarChar, 30, "ContactName"));
  422. this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ContactTitle", System.Data.SqlDbType.NVarChar, 30, "ContactTitle"));
  423. this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Address", System.Data.SqlDbType.NVarChar, 60, "Address"));
  424. this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@City", System.Data.SqlDbType.NVarChar, 15, "City"));
  425. this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Region", System.Data.SqlDbType.NVarChar, 15, "Region"));
  426. this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@PostalCode", System.Data.SqlDbType.NVarChar, 10, "PostalCode"));
  427. this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Country", System.Data.SqlDbType.NVarChar, 15, "Country"));
  428. this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Phone", System.Data.SqlDbType.NVarChar, 24, "Phone"));
  429. this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Fax", System.Data.SqlDbType.NVarChar, 24, "Fax"));
  430. 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));
  431. 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));
  432. 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));
  433. 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));
  434. 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));
  435. 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));
  436. 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));
  437. 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));
  438. 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));
  439. 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));
  440. 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));
  441. // 
  442. // sqlDeleteCommand1
  443. // 
  444. 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)";
  445. this.sqlDeleteCommand1.Connection = this.sqlConnection1;
  446. 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));
  447. 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));
  448. 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));
  449. 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));
  450. 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));
  451. 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));
  452. 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));
  453. 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));
  454. 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));
  455. 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));
  456. 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));
  457. // 
  458. // Form1
  459. // 
  460. this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
  461. this.ClientSize = new System.Drawing.Size(328, 365);
  462. this.Controls.AddRange(new System.Windows.Forms.Control[] {
  463.   this.groupBox1,
  464.   this.comboBox1,
  465.   this.label1});
  466. this.Name = "Form1";
  467. this.Text = "查询顾客信息";
  468. ((System.ComponentModel.ISupportInitialize)(this.dataSet1)).EndInit();
  469. this.groupBox1.ResumeLayout(false);
  470. this.ResumeLayout(false);
  471. }
  472. #endregion
  473. /// <summary>
  474. /// 应用程序的主入口点。
  475. /// </summary>
  476. [STAThread]
  477. static void Main() 
  478. {
  479. Application.Run(new Form1());
  480. }
  481. private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs e)
  482. {
  483. //获得顾客名称
  484. string s=this.comboBox1.Text;
  485. //对具体显示顾客信息的组件进行数据绑定
  486. DataBinding(s);
  487. }
  488. private void DataBinding(string name)
  489.    {
  490.              //设置查询字符串
  491.  string commString="SELECT * From Customers WHERE "+ "ContactName="+"'"+name+"'";
  492.  //新建一个SqlCommand对象
  493.  SqlCommand comm=new SqlCommand() ;
  494.      //设置SqlCommand对象的查询语句
  495.  comm.CommandText=commString;  
  496.  //设置SqlCommand对象的连接
  497.  comm.Connection=this.sqlConnection1;
  498.      //新建一个数据集存贮查询结果   
  499.    DataSet dataSet2=new DataSet();
  500.  //改变数据适配器对象的查询语句 
  501.  this.sqlDataAdapter1.SelectCommand=comm;
  502.  //填充数据集
  503.  this.sqlDataAdapter1.Fill(dataSet2,"Customers");
  504.              //具体对每个控件进行数据绑定
  505.  //绑定前要清空以前的绑定
  506.           this.textBox1.DataBindings.Clear();
  507.  this.textBox1.DataBindings.Add("Text",dataSet2,"Customers.CustomerID");
  508.  this.textBox2.DataBindings.Clear();
  509.  this.textBox2.DataBindings.Add("Text",dataSet2,"Customers.CompanyName");
  510.  this.textBox3.DataBindings.Clear();
  511.  this.textBox3.DataBindings.Add("Text",dataSet2,"Customers.ContactName");
  512.  this.textBox4.DataBindings.Clear();
  513.  this.textBox4.DataBindings.Add("Text",dataSet2,"Customers.ContactTitle");
  514.  this.textBox5.DataBindings.Clear();
  515.  this.textBox5.DataBindings.Add("Text",dataSet2,"Customers.Address");
  516.       this.textBox6.DataBindings.Clear();
  517.    this.textBox6.DataBindings.Add("Text",dataSet2,"Customers.City");
  518.  this.textBox7.DataBindings.Clear();
  519.  this.textBox7.DataBindings.Add("Text",dataSet2,"Customers.Region");
  520.  this.textBox8.DataBindings.Clear();
  521.  this.textBox8.DataBindings.Add("Text",dataSet2,"Customers.PostalCode");
  522.       this.textBox9.DataBindings.Clear();
  523.  this.textBox9.DataBindings.Add("Text",dataSet2,"Customers.Country");
  524.  this.textBox10.DataBindings.Clear();
  525.  this.textBox10.DataBindings.Add("Text",dataSet2,"Customers.Phone");
  526.  this.textBox11.DataBindings.Clear();
  527.  this.textBox11.DataBindings.Add("Text",dataSet2,"Customers.Fax");
  528. }
  529. }
  530. }