Exemplo n.º 1
0
        //insert contact
        public bool insert_tel_numbers(tel_number t)
        {
            bool          is_success = false;
            SqlConnection conn       = new SqlConnection(myconstring);

            try
            {
                string     sql = "INSERT INTO tel_numbers(fname,lname,tel,address,gender) VALUES (@fname,@lname,@tel,@address,@gender)";
                SqlCommand cmd = new SqlCommand(sql, conn);
                cmd.Parameters.AddWithValue("@fname", t.firstName);
                cmd.Parameters.AddWithValue("@lname", t.lastName);
                cmd.Parameters.AddWithValue("@tel", t.tel);
                cmd.Parameters.AddWithValue("@address", t.addess);
                cmd.Parameters.AddWithValue("@gender", t.gender);

                conn.Open();
                int rows = cmd.ExecuteNonQuery();
                if (rows > 0)
                {
                    is_success = true;
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
                conn.Close();
            }

            return(is_success);
        }
Exemplo n.º 2
0
        //update data
        public bool update_contact(tel_number t)
        {
            bool          issuccess = false;
            SqlConnection conn      = new SqlConnection(myconstring);

            try
            {
                string     sql = "UPDATE tel_numbers SET fname=@fname,lname=@lname,tel=@tel,address=@address,gender=@gender WHERE id=@id";
                SqlCommand cmd = new SqlCommand(sql, conn);
                cmd.Parameters.AddWithValue("@id", t.contactId);
                cmd.Parameters.AddWithValue("@fname", t.firstName);
                cmd.Parameters.AddWithValue("@lname", t.lastName);
                cmd.Parameters.AddWithValue("@tel", t.tel);
                cmd.Parameters.AddWithValue("@address", t.addess);
                cmd.Parameters.AddWithValue("@gender", t.gender);

                conn.Open();
                int rows = cmd.ExecuteNonQuery();
                if (rows > 0)
                {
                    issuccess = true;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                conn.Close();
            }
            return(issuccess);
        }
Exemplo n.º 3
0
        //delete contact
        public bool delete_contact(tel_number t)
        {
            bool          issuccess = false;
            SqlConnection conn      = new SqlConnection(myconstring);

            try
            {
                string     sql = "DELETE FROM tel_numbers WHERE id=@id";
                SqlCommand cmd = new SqlCommand(sql, conn);
                cmd.Parameters.AddWithValue("@id", t.contactId);
                conn.Open();
                int rows = cmd.ExecuteNonQuery();
                if (rows > 0)
                {
                    issuccess = true;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                conn.Close();
            }
            return(issuccess);
        }