ADOSample5.cs
上传用户:lxycoco
上传日期:2022-07-21
资源大小:38457k
文件大小:4k
源码类别:

C#编程

开发平台:

Others

  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.Xml;
  8. using System.Data.SqlClient;
  9. using System.IO;
  10. namespace Wrox.ProCSharp.Xml.ADOSample5 
  11. {
  12. /// <summary>
  13. /// Summary description for Form1.
  14. /// </summary>
  15. public class Form1 : System.Windows.Forms.Form
  16. {
  17. private System.Windows.Forms.ListBox listBox1;
  18. private System.Windows.Forms.Button button1;
  19. private System.Windows.Forms.DataGrid dataGrid1;
  20. /// <summary>
  21. /// Required designer variable.
  22. /// </summary>
  23. private System.ComponentModel.Container components = null;
  24. private XmlDocument doc=new XmlDocument();
  25. public Form1()
  26. {
  27. //
  28. // Required for Windows Form Designer support
  29. //
  30. InitializeComponent();
  31. //
  32. // TODO: Add any constructor code after InitializeComponent call
  33. //
  34. }
  35. /// <summary>
  36. /// Clean up any resources being used.
  37. /// </summary>
  38. protected override void Dispose( bool disposing )
  39. {
  40. if( disposing )
  41. {
  42. if (components != null) 
  43. {
  44. components.Dispose();
  45. }
  46. }
  47. base.Dispose( disposing );
  48. }
  49. #region Windows Form Designer generated code
  50. /// <summary>
  51. /// Required method for Designer support - do not modify
  52. /// the contents of this method with the code editor.
  53. /// </summary>
  54. private void InitializeComponent()
  55. {
  56. this.dataGrid1 = new System.Windows.Forms.DataGrid();
  57. this.button1 = new System.Windows.Forms.Button();
  58. this.listBox1 = new System.Windows.Forms.ListBox();
  59. ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
  60. this.SuspendLayout();
  61. // 
  62. // dataGrid1
  63. // 
  64. this.dataGrid1.Anchor = (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
  65. | System.Windows.Forms.AnchorStyles.Left) 
  66. | System.Windows.Forms.AnchorStyles.Right);
  67. this.dataGrid1.DataMember = "";
  68. this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
  69. this.dataGrid1.Location = new System.Drawing.Point(0, 248);
  70. this.dataGrid1.Name = "dataGrid1";
  71. this.dataGrid1.Size = new System.Drawing.Size(392, 176);
  72. this.dataGrid1.TabIndex = 2;
  73. // 
  74. // button1
  75. // 
  76. this.button1.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
  77. this.button1.Location = new System.Drawing.Point(164, 432);
  78. this.button1.Name = "button1";
  79. this.button1.TabIndex = 1;
  80. this.button1.Text = "Load Data";
  81. this.button1.Click += new System.EventHandler(this.button1_Click);
  82. // 
  83. // listBox1
  84. // 
  85. this.listBox1.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
  86. | System.Windows.Forms.AnchorStyles.Right);
  87. this.listBox1.Name = "listBox1";
  88. this.listBox1.Size = new System.Drawing.Size(392, 238);
  89. this.listBox1.TabIndex = 0;
  90. // 
  91. // Form1
  92. // 
  93. this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
  94. this.ClientSize = new System.Drawing.Size(395, 488);
  95. this.Controls.AddRange(new System.Windows.Forms.Control[] {
  96.   this.dataGrid1,
  97.   this.button1,
  98.   this.listBox1});
  99. this.Name = "Form1";
  100. this.Text = "Form1";
  101. ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
  102. this.ResumeLayout(false);
  103. }
  104. #endregion
  105. /// <summary>
  106. ///  The main entry point for the application.
  107. /// </summary>
  108. [STAThread]
  109. static void Main() 
  110. {
  111. try
  112. {
  113. Application.Run(new Form1());
  114. }
  115. catch(System.IO.FileNotFoundException){}
  116. }
  117. //ADOSample5form.cs
  118. private void button1_Click(object sender, System.EventArgs e)
  119. {
  120. //create the DataSet
  121. DataSet ds=new DataSet("XMLProducts");
  122. //read in the xml document
  123. ds.ReadXml("..\..\..\SuppProd.xml");
  124.    
  125. //load data into grid
  126. dataGrid1.DataSource=ds;
  127. dataGrid1.DataMember="products";
  128. //load the listbox with table, column and datatype info
  129. foreach(DataTable dt in ds.Tables)  
  130. {
  131. listBox1.Items.Add(dt.TableName);
  132. foreach(DataColumn col in dt.Columns) 
  133. {
  134. listBox1.Items.Add
  135. ('t' + col.ColumnName + " - " + col.DataType.FullName);
  136. }
  137. }
  138.     
  139. }
  140. }
  141. }