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

namespace Amozeshgah
{
   
        class DataAccess
        {
            //public string ServerName;
            public string DBName = "Amozeshgah.mdf";
           // public string username;
            
            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();
            }

        }
    
}
