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

namespace KhadamateDarmaniCS
{
    class FirstClass
    {
        SqlConnection con;
        public SqlCommand cmd;
        DataTable dt;
        SqlDataAdapter da;

        public FirstClass()
        {
            con = new SqlConnection("server = (local); Database = BimehKhadamateDarmani; trusted_connection = yes;");
            cmd = new SqlCommand();
            dt = new DataTable();
            cmd.Connection = con;
            da = new SqlDataAdapter(cmd);
        }

        public DataTable dbOut(string sql)
        {
            cmd.CommandText = sql;
            con.Open();
            da.Fill(dt);
            con.Close();
            return dt;
        }



        public DataTable SP_dbOut(string SP_Name)
        {
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = SP_Name;
            con.Open();
            da.Fill(dt);
            con.Close();
            return dt;
        }

        public void exeCommand(string strName)
        {
            con.Open();
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = strName;
            cmd.ExecuteNonQuery();
            con.Close();

        }
        public void exeCommand1(string strName)
        {
            try
            {
                cmd.CommandText = strName;
                con.Open();
                cmd.ExecuteNonQuery();
            }
            catch { }
            finally
            {
                con.Close();
            }

        }
    }
}
