using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace Library
{
    class DataAccess
    {
        SqlConnection con;
        SqlCommand cmd;
        SqlDataAdapter da;
        public DataAccess()
        {
            con = new SqlConnection();
            cmd = new SqlCommand();
            da = new SqlDataAdapter();
            cmd.Connection = con;
            da.SelectCommand = cmd;
        }
        public void Connect()
        {
            string cs = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Library.mdf;Integrated Security=True;User Instance=True";
            con.ConnectionString = cs;
            con.Open();
        }
        public void DisConnect()
        {
            con.Close();
        }
        public DataTable Select(string sql)
        {
            DataTable dt = new DataTable();
            cmd.CommandText = sql;
            da.Fill(dt);
            return dt;
        }
        public void DoCommand(string sql)
        {
            cmd.CommandText = sql;
            cmd.ExecuteNonQuery();
        }
    }
}
