using System; using System.Collections.Generic; using System.Linq; using System.Web; //************************************************ using System.Data; ////------------------------------mohem using System.Data.SqlClient; /////****************** moheeeem using System.Data.SqlTypes; using System.Data.Sql; /// /// Summary description for dbConnect /// public class dbConnect { public string dbName; // public string cstr = "server=(local);database=resourceDB;trusted_connection=yes;"; public string cstr = "server=.;database=naghshdb1;trusted_connection=yes;"; //public string cstr = "Data Source=192.168.1.1;Initial Catalog=databaseName;User ID=loginName;Password=loginPass"; //public string cstr = "Data Source=192.168.1.1;Initial Catalog=databaseName;User ID=sa;Password=......."; private SqlConnection con; private SqlCommand cmd; private SqlDataAdapter da; private DataTable dt; private DataSet ds; public string lasterror; // akharin error ettefagh oftade // public ham migim bashe public dbConnect() { // // TODO: Add constructor logic here // try { con = new SqlConnection(); con.ConnectionString = cstr; cmd = new SqlCommand(); cmd.Connection = con; da = new SqlDataAdapter(cmd); dt = new DataTable(); ds = new DataSet(); } catch (Exception ex) { this.lasterror = ex.Message; } } public DataTable selectCmd(string sql) // select , search ...... DA ..... { try { con.Open(); cmd.CommandText = sql; dt.Clear(); da.Fill(dt); con.Close(); } catch (Exception ex) { this.lasterror = ex.Message; } finally { con.Close(); } return dt; } public void executeCmd(string sql) // for update or delete or insert { try { con.Open(); cmd.CommandText = sql; cmd.ExecuteNonQuery(); // ejraye ...delete ya update ya insert con.Close(); } catch (Exception ex) { this.lasterror = ex.Message; } finally { con.Close(); } } }