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

📄 ex-14-04

📁 Programming Csharp Source Code(代码) Programming Csharp Source Code
💻
字号:
// Example 14-04: Customizing a Dataset

namespace ProgrammingCSharpWindows.Form
{
   using System;
   using System.Drawing;
   using System.Collections;
   using System.ComponentModel;
   using System.Windows.Forms;
   using System.Data;
   using System.Data.SqlClient;

   public class ADOForm1 : System.Windows.Forms.Form
   {
      private System.ComponentModel.Container components;
      private System.Windows.Forms.DataGrid dataGrid1;



      // private System.Data.ADO.ADOConnection myConnection;
      private System.Data.SqlClient.SqlConnection myConnection;
      private System.Data.DataSet myDataSet;
      private System.Data.SqlClient.SqlCommand myCommand;
      private System.Data.SqlClient.SqlDataAdapter DataAdapter;
     
      public ADOForm1()
      {
         InitializeComponent();

         // create the connection object and open it
         string connectionString = 
            "server=Neptune; uid=sa; pwd=oWenmEany; database=northwind";         
         myConnection = new  
            System.Data.SqlClient.SqlConnection(connectionString);
         myConnection.Open();

         // create the DataSet and set a property
         myDataSet = new System.Data.DataSet();
         myDataSet.CaseSensitive=true;

         // create the SqlCommand  object and assign the
         // connection and the select statement
         myCommand = new System.Data.SqlClient.SqlCommand();
         myCommand.Connection=myConnection;
         myCommand.CommandText = "Select * from Customers";

         // create the DataAdapter object and pass in the
         // SQL Command object and establish the table mappings
         DataAdapter = new System.Data.SqlClient.SqlDataAdapter();
         DataAdapter.SelectCommand= myCommand;
         DataAdapter.TableMappings.Add("Table","Customers");

         // Tell the DataAdapter object to fill the DataSet
         DataAdapter.Fill(myDataSet);

         // display it in the grid
         dataGrid1.DataSource=
            myDataSet.Tables["Customers"].DefaultView;  
      }

      public override void Dispose()
      {
         base.Dispose();
         components.Dispose();
      }

      private void InitializeComponent()
      {
         this.components = new System.ComponentModel.Container ();
         this.dataGrid1 = new System.Windows.Forms.DataGrid ();
         dataGrid1.BeginInit ();
         dataGrid1.Location = new System.Drawing.Point (24, 32);
         dataGrid1.Size = new System.Drawing.Size (480, 408);
         dataGrid1.DataMember = "";
         dataGrid1.TabIndex = 0;
         this.Text = "ADOFrm1";
         this.AutoScaleBaseSize = new System.Drawing.Size (5, 13);
         this.ClientSize = new System.Drawing.Size (536, 501);
         this.Controls.Add (this.dataGrid1);
         dataGrid1.EndInit ();
      }
 
      public static void Main(string[] args) 
      {
         Application.Run(new ADOForm1());
      }
   }
}

⌨️ 快捷键说明

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