Exemplo n.º 1
0
        public bool delete(CustomerClass c)
        {
            bool          isSuccess = false;
            SqlConnection conn      = new SqlConnection(connString);

            try
            {
                string sql = "DELETE FROM CusDetails WHERE CustomerID=@CustomerID";

                SqlCommand cmd = new SqlCommand(sql, conn);

                cmd.Parameters.AddWithValue("@CustomerID", c.CustomerID);

                conn.Open();
                int rows = cmd.ExecuteNonQuery();

                if (rows > 0)
                {
                    isSuccess = true;
                }
                else
                {
                    isSuccess = false;
                }
            }
            catch (Exception e)
            {
            }
            finally
            {
                conn.Close();
            }
            return(isSuccess);
        }
Exemplo n.º 2
0
        //update data in database

        public bool update(CustomerClass c)
        {
            bool isSuccess = false;

            SqlConnection conn = new SqlConnection(connString);

            try
            {
                string     sql = "UPDATE CusDetails SET Name='" + c.Name + "', NIC='" + c.NIC + "', Address='" + c.Address + "', PhoneNumber='" + c.PhoneNumber + "', EMail='" + c.EMail + "', Gender='" + c.Gender + "' WHERE CustomerID='" + c.CustomerID + "'";
                SqlCommand cmd = new SqlCommand(sql, conn);

                conn.Open();
                int rows = cmd.ExecuteNonQuery();

                if (rows > 0)
                {
                    isSuccess = true;
                }
                else
                {
                    isSuccess = false;
                }
            }
            catch (Exception e)
            {
            }
            finally
            {
                conn.Close();
            }
            return(isSuccess);
        }
Exemplo n.º 3
0
        //inserting data into database

        public bool insert(CustomerClass c)
        {
            bool isSuccess = false;

            SqlConnection conn = new SqlConnection(connString);

            try
            {
                string sql = "INSERT INTO CusDetails (Name, NIC, Address, PhoneNumber, EMail, Gender, EntryDate) VALUES (@Name, @NIC, @Address, @PhoneNumber, @EMail, @Gender, @EntryDate)";

                SqlCommand cmd = new SqlCommand(sql, conn);

                cmd.Parameters.AddWithValue("@Name", c.Name);
                cmd.Parameters.AddWithValue("@NIC", c.NIC);
                cmd.Parameters.AddWithValue("@Address", c.Address);
                cmd.Parameters.AddWithValue("@PhoneNumber", c.PhoneNumber);
                cmd.Parameters.AddWithValue("@EMail", c.EMail);
                cmd.Parameters.AddWithValue("@Gender", c.Gender);
                cmd.Parameters.AddWithValue("@EntryDate", DateTime.Now);

                conn.Open();
                int rows = cmd.ExecuteNonQuery();

                if (rows > 0)
                {
                    isSuccess = true;
                }
                else
                {
                    isSuccess = false;
                }
            }
            catch (System.Data.SqlClient.SqlException sqlExceptione)
            {
                System.Windows.Forms.MessageBox.Show(sqlExceptione.Message);
            }
            finally
            {
                conn.Close();
            }
            return(isSuccess);
        }