April 2018
Intermediate to advanced
300 pages
7h 41m
English
Here is a simple DataManager class that uses a System.Data.SQL API to perform database operations on an SQL server database:
public class DataManager : IDisposable { private SqlConnection _connection; //Returns the list of users from database public DataTable GetUsers() { //Invoke OpenConnection to instantiate the _connection object OpenConnection(); //Executing command in a using block to dispose command object using(var command =new SqlCommand()) { command.Connection = _connection; command.CommandText = "Select * from Users"; //Executing reader in a using block to dispose reader object using (var reader = command.ExecuteReader()) { var dt = new DataTable(); dt.Load(reader); return dt; } } } private void OpenConnection() ...