DataGridView + DataAdapter 使用方法

 

   DataGridView + DataAdapter 使用方法
 
   using System.Data.SqlClient;
 
   private void button1_Click(object sender, EventArgs e)
   {
      String connectionString1 = "Data Source=.\\SqlExpress; Initial Catalog=Soccer; Integrated Security=SSPI";
      SqlConnection con1 = new SqlConnection(connectionString1);
      con1.Open();
 
      String SqlString1 = "SELECT Player_ID, Player_Name FROM dbo.Player";
 
      SqlDataAdapter Adapter = new SqlDataAdapter(SqlString1.ToString(), con1);
      DataSet ds = new DataSet();
 
      Adapter.Fill(ds);
 
      this.dataGridView1.DataSource = ds.Tables[0].DefaultView;
 
      ds.Dispose();
      con1.Dispose();
   }