Beispiel #1
0
        //Method to update data from our application
        public bool Update(InternInfoEntry foo)
        {
            bool isSuccess = false;
            //DB connection
            SqlConnection conn = new SqlConnection(myConnString);

            try
            {
                string sql = "UPDATE internship SET Company=@company, Position=@position, date_app=@date_app, date_resp=@date_resp, response=@response, followUp=@followUp, additionalinfo=@additionalInfo, active=@active " +
                             " WHERE company=@company";
                SqlCommand cmd = new SqlCommand(sql, conn);
                cmd.Parameters.AddWithValue("@company", foo.Company);
                cmd.Parameters.AddWithValue("@position", foo.PositionProp);
                cmd.Parameters.AddWithValue("@date_app", foo.DateForApplication);
                cmd.Parameters.AddWithValue("@date_resp", foo.DateForResponse);
                cmd.Parameters.AddWithValue("@response", foo.Response);
                cmd.Parameters.AddWithValue("@followUp", foo.FollowUp);
                cmd.Parameters.AddWithValue("@additionalInfo", foo.AdditionalInfo);
                cmd.Parameters.AddWithValue("@active", foo.Active);

                conn.Open();
                int rows = cmd.ExecuteNonQuery();
                if (rows > 0)
                {
                    isSuccess = true;
                }
            }
            catch (Exception e) { Console.Write(e.StackTrace); }
            finally { conn.Close(); }



            return(isSuccess);
        }
Beispiel #2
0
        //Inserting data => database
        public bool Insert(InternInfoEntry foo)
        {
            //basic return type, default = false
            bool isSucces = false;

            //DB connection
            SqlConnection conn = new SqlConnection(myConnString);

            try
            {
                //Create sql query
                string sql = "INSERT INTO internship (company, position, date_app, date_resp, response, followup, additionalInfo, active) " +
                             "VALUES(@company, @position, @date_app, @date_resp, @response, @followup, @additionalInfo, @active)";

                //create sql command using sql and conn
                SqlCommand cmd = new SqlCommand(sql, conn);

                //Create parameters to add data
                cmd.Parameters.AddWithValue("@company", foo.Company);
                cmd.Parameters.AddWithValue("@position", foo.PositionProp);
                cmd.Parameters.AddWithValue("@date_app ", foo.DateForApplication);
                cmd.Parameters.AddWithValue("@date_resp ", foo.DateForResponse);
                cmd.Parameters.AddWithValue("@response", foo.Response);
                cmd.Parameters.AddWithValue("@followUp", foo.FollowUp);
                cmd.Parameters.AddWithValue("@additionalInfo", foo.AdditionalInfo);
                cmd.Parameters.AddWithValue("@active", foo.Active);
                //Open connection
                conn.Open();
                int rows = cmd.ExecuteNonQuery();
                //check if the query was succesfull
                if (rows > 0)
                {
                    isSucces = true;
                }
            }
            catch (Exception e) { Console.WriteLine(e.StackTrace); }
            finally { conn.Close(); }
            return(isSucces);
        }
Beispiel #3
0
        public bool Delete(InternInfoEntry foo)
        {
            bool isSuccess = false;
            //DB connection
            SqlConnection conn = new SqlConnection(myConnString);

            try
            {
                string     sql = "DELETE FROM internship WHERE company=@company ";
                SqlCommand cmd = new SqlCommand(sql, conn);
                cmd.Parameters.AddWithValue("@company", foo.Company);
                conn.Open();
                int rows = cmd.ExecuteNonQuery();
                if (rows > 0)
                {
                    isSuccess = true;
                }
            }
            catch (Exception e) { }
            finally { conn.Close(); }
            return(isSuccess);
        }