Winform 加载datagridview
string str = @"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=Test;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"; SqlConnection sqlConnection = new SqlConnection(str); sqlConnection.Open(); string sql = "select *from Student"; SqlDataAdapter dataAdapter = new SqlDataAdapter(sql, sqlConnection); DataSet dataSet = new DataSet(); dataAdapter.Fill(dataSet); this.dataGridView1.DataSource = dataSet.Tables[0].DefaultView; sqlConnection.Close();