Non-link access to the database-the queried Dataset is stored in Dataset ., Connection Mode dataset
Private void Button_Click_1 (object sender, RoutedEventArgs e) {// access the database in non-link mode, // 1 create a connection object (connection string) using (SqlConnection conn = new SqlConnection (SQLHelper. connectionString) {// 2. create data adapter object using (SqlDataAdapter sda = new SqlDataAdapter ("select * from Student", conn) {// 3. open the database connection (this step can be omitted) conn. open (); DataSet ds = new DataSet (); // 4. send command sda. fill (ds); // 5. close the connection // Note: Because the using code block is used here, closing the connection can save DataRowCollection drCollection = ds. tables [0]. rows; for (int I = 0; I <drCollection. count; I ++) {DataRow dr = drCollection [I]; MessageBox. show (dr ["s_Name"]. toString ());}}}}
Note: dataset occupies the memory. We can query the memory size of your data.