Esempio n. 1
0
        public bool Delete(ContactsClass C)
        {
            bool isSuccessful = false;

            SqlConnection conn = new SqlConnection(myconnstring);


            try
            {
                string sql = "DELETE FROM Table_0 WHERE @Contactid=Contactid";

                SqlCommand cmd = new SqlCommand(sql, conn);
                cmd.Parameters.AddWithValue("@Contactid", C.ContactsBox);
                //Open Connectiong
                conn.Open();
                int rows = cmd.ExecuteNonQuery();
                if (rows > 0)
                {
                    isSuccessful = true;
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
                conn.Close();
            }


            return(isSuccessful);
        }
Esempio n. 2
0
        public bool Insert(ContactsClass C)
        {
            //Creating default return type and setting it's value to false
            bool isSuccess = false;

            SqlConnection conn = new SqlConnection(myconnstring);

            try
            {
                string     sql = "INSERT INTO Table_0 (FirstName, Surname, ContactNumb,Address,Gender) VALUES (@FirstName, @Surname, @ContactNumb,@Address,@Gender)";
                SqlCommand cmd = new SqlCommand(sql, conn);
                // Create parametrs to add data
                cmd.Parameters.AddWithValue("@FirstName", C.NamesBox);
                cmd.Parameters.AddWithValue("@Surname", C.SurnamesBox);
                cmd.Parameters.AddWithValue("@ContactNumb", C.NumbersBox);
                cmd.Parameters.AddWithValue("@Address", C.textsBox1);
                cmd.Parameters.AddWithValue("@Gender", C.ChoosesGender);

                conn.Open();
                int rows = cmd.ExecuteNonQuery();
                // if the query runs successfully than the number of rows will be greater than 0
                if (rows > 0)
                {
                    isSuccess = true;
                }
            }
            catch (Exception ex)
            {
            }finally
            {
                conn.Close();
            }

            return(isSuccess);
        }
Esempio n. 3
0
        // Method to update info in the table

        public bool Update(ContactsClass C)
        {
            // Create default boolean
            bool          isSuccessful = false;
            SqlConnection conn         = new SqlConnection(myconnstring);

            try
            {
                String sql = "UPDATE Table_0 SET FirstName=@FirstName, Surname=@Surname, ContactNumb=@ContactNumb,Address=@Address,Gender=@Gender WHERE Contactid=@Contactid";

                //Creating an SQL Command
                SqlCommand cmd = new SqlCommand(sql, conn);
                // Create Parametrs
                cmd.Parameters.AddWithValue("@FirstName", C.NamesBox);
                cmd.Parameters.AddWithValue("@Surname", C.SurnamesBox);
                cmd.Parameters.AddWithValue("@ContactNumb", C.NumbersBox);
                cmd.Parameters.AddWithValue("@Address", C.textsBox1);
                cmd.Parameters.AddWithValue("@Gender", C.ChoosesGender);
                cmd.Parameters.AddWithValue("@Contactid", C.ContactsBox);
                // Open Connection
                conn.Open();

                int rows = cmd.ExecuteNonQuery();
                // IF the size of the query is bigger than 0, than show smth
                if (rows > 0)
                {
                    isSuccessful = true;
                }
            }
            catch (Exception ex) {
            } finally
            {
                conn.Close();
            }
            return(isSuccessful);
        }