public List <UniteType> GetAll() { SqlConnection Connection = DBGate.GetConnection(); string SelectAll = " select * from UniteType "; SqlCommand cmd = new SqlCommand(SelectAll, Connection); List <UniteType> lst = new List <UniteType>(); try { Connection.Open(); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { UniteType _obj = new UniteType(); _obj.ID = int.Parse(reader["ID"].ToString()); _obj.UniteName = reader["UniteName"].ToString(); lst.Add(_obj); } } catch (SqlException ex) { frmDone frmerror = new frmDone(ex.ToString()); frmerror.ShowDialog(); } finally { Connection.Close(); } return(lst); }
public DAL.UniteType GetByID(int ID) { SqlConnection Connection = DBGate.GetConnection(); string SelectByID = "Select * from UniteType where ID = @ID "; SqlCommand cmd = new SqlCommand(SelectByID, Connection); cmd.Parameters.AddWithValue("@ID", ID); UniteType _obj = new UniteType(); try { Connection.Open(); SqlDataReader reader = cmd.ExecuteReader(); if (reader.Read()) { _obj.ID = int.Parse(reader["ID"].ToString()); _obj.UniteName = reader["UniteName"].ToString(); } } catch (SqlException ex) { frmDone frmerror = new frmDone(ex.ToString()); frmerror.ShowDialog(); } finally { Connection.Close(); } return(_obj); }