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();

 

posted @ 2019-03-15 16:16  JackJu  阅读(374)  评论(0编辑  收藏  举报