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

namespace Library
{
    class DataAccess
    {
        public string ServerName;
        public string DBName = "libdb.mdf";
        public string username;
        public string password;
        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|\\{0};Integrated security=true;user Instance=true";
            cs = string.Format(cs, this.DBName);
            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();
        }

    }
}
