Example #1
0
        public bool Delete(contactClass c)
        {
            //var connectionString = ConfigurationManager.ConnectionStrings["connstring"].ConnectionString;
            bool          isSuccess = false;
            SqlConnection conn      = new SqlConnection(conString);

            try
            {
                string     sql = "DELETE FROM tbl_contact WHERE ContactID=@ContactID";
                SqlCommand cmd = new SqlCommand(sql, conn);
                cmd.Parameters.AddWithValue("@ContactID", c.ContactID);

                conn.Open();
                int row = cmd.ExecuteNonQuery();
                if (row > 0)
                {
                    isSuccess = true;
                }
                else
                {
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
                conn.Close();
            }
            return(isSuccess);
        }
Example #2
0
        //insert data into database
        public bool insert(contactClass c)
        {
            //var  connectionString = ConfigurationManager.ConnectionStrings["connstring"].ConnectionString;

            bool          isSuccess = false;
            SqlConnection conn      = new SqlConnection(conString);

            try
            {
                string     sql = "INSERT INTO tbl_contact(FirstName,LastName,ContactNO,Address,Gender) VALUES (@FirstName,@LastName,@ContactNO,@Address,@Gender)";
                SqlCommand cmd = new SqlCommand(sql, conn);
                cmd.Parameters.AddWithValue("@FirstName", c.FirstName);
                cmd.Parameters.AddWithValue("@LastName", c.LastName);
                cmd.Parameters.AddWithValue("@ContactNO", c.ContactNO);
                cmd.Parameters.AddWithValue("@Address", c.Address);
                cmd.Parameters.AddWithValue("@Gender", c.Gender);

                conn.Open();
                int row = cmd.ExecuteNonQuery();
                if (row > 0)
                {
                    isSuccess = true;
                }
                else
                {
                    isSuccess = true;
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
                conn.Close();
            }
            return(isSuccess);
        }
Example #3
0
        public bool Update(contactClass c)
        {
            //var connectionString = ConfigurationManager.ConnectionStrings["connstring"].ConnectionString;
            bool          isSuccess = false;
            SqlConnection conn      = new SqlConnection(conString);

            try
            {
                string     sql = "UPDATE tbl_contact SET FirstName=@FirstName,LastName=@LastName,ContactNO=@ContactNO,Address=@Address,Gender=@Gender WHERE ContactID=@ContactID";
                SqlCommand cmd = new SqlCommand(sql, conn);
                cmd.Parameters.AddWithValue("@FirstName", c.FirstName);
                cmd.Parameters.AddWithValue("@LastName", c.LastName);
                cmd.Parameters.AddWithValue("@ContactNO", c.ContactNO);
                cmd.Parameters.AddWithValue("@Address", c.Address);
                cmd.Parameters.AddWithValue("@Gender", c.Gender);

                conn.Open();
                int row = cmd.ExecuteNonQuery();
                if (row > 0)
                {
                    isSuccess = true;
                }
                else
                {
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
                conn.Close();
            }
            return(isSuccess);
        }