Esempio n. 1
0
        public Company GetStudentById(int companyId)
        {
            SqlConnection connection = new SqlConnection(connectionString);

            string query = "SELECT * FROM company WHERE company_id = '" + companyId + "'";

            SqlCommand command = new SqlCommand(query, connection);

            connection.Open();
            SqlDataReader reader = command.ExecuteReader();

            Company company = null;

            while (reader.Read())
            {

                if (company == null)
                {
                    company = new Company();
                }
                company.CompanyId = int.Parse(reader["company_id"].ToString());
                company.Name = reader["company_name"].ToString();
                company.Address = reader["address"].ToString();

            }

            reader.Close();
            connection.Close();

            return company;
        }
Esempio n. 2
0
        public void Delete(Company company)
        {
            SqlConnection connection = new SqlConnection(connectionString);

            string query = "Delete from company WHERE company_id =" + company.CompanyId;

            SqlCommand command = new SqlCommand(query, connection);

            connection.Open();

            command.ExecuteNonQuery();

            connection.Close();
        }
Esempio n. 3
0
 public void Update(Company company)
 {
     myCompanyGateway.Update(company);
     //MessageBox.Show("Update Success");
 }
Esempio n. 4
0
 public bool Save(Company company)
 {
     return myCompanyGateway.Save(company) > 0;
 }
Esempio n. 5
0
 public void Delete(Company company)
 {
     myCompanyGateway.Delete(company);
 }
Esempio n. 6
0
        public int Save(Company company)
        {
            SqlConnection sqlConnection = new SqlConnection(connectionString);
            string query = "INSERT INTO company VALUES('" + company.Name + "','" + company.Address + "')";
            SqlCommand sqlCommand = new SqlCommand(query, sqlConnection);
            sqlConnection.Open();

            int rowAffected = sqlCommand.ExecuteNonQuery();

            sqlConnection.Close();

            return rowAffected;
        }
Esempio n. 7
0
        public void Update(Company company)
        {
            SqlConnection connection = new SqlConnection(connectionString);

            string query = "UPDATE company SET company_name = '" + company.Name + "', address= '" + company.Address + "' WHERE company_id =" + company.CompanyId;

            SqlCommand command = new SqlCommand(query, connection);

            connection.Open();

            command.ExecuteNonQuery();

            connection.Close();
        }
Esempio n. 8
0
 public List<Company> ShowAll()
 {
     List<Company> companieslList = new List<Company>();
     SqlConnection sqlConnection = new SqlConnection(connectionString);
     string query = "SELECT * FROM company";
     SqlCommand command = new SqlCommand(query, sqlConnection);
     sqlConnection.Open();
     SqlDataReader myReader = command.ExecuteReader();
     while (myReader.Read())
     {
         Company company = new Company();
         company.CompanyId = Convert.ToInt32(myReader["company_id"].ToString());
         company.Name = myReader["company_name"].ToString();
         company.Address = myReader["address"].ToString();
         companieslList.Add(company);
     }
     return companieslList;
 }