Example #1
0
        public bool Insert(PersonClass person)
        {
            bool issuccess = false;

            SqlConnection conn = new SqlConnection(connstring);
            SqlCommand    cmd  = new SqlCommand("INSERT INTO Person(FirstName, LastName, Age) VALUES (@FirstName, @LastName, @Age)", conn);

            cmd.Parameters.AddWithValue("@FirstName", person.FirstName);
            cmd.Parameters.AddWithValue("@LastName", person.LastName);
            cmd.Parameters.AddWithValue("@Age", person.Age);
            conn.Open();
            int rows = cmd.ExecuteNonQuery();

            conn.Close();
            if (rows > 0)
            {
                issuccess = true;
                return(issuccess);
            }
            return(issuccess);
        }
Example #2
0
        public bool Update(PersonClass person)
        {
            bool issuccess = false;

            SqlConnection conn = new SqlConnection(connstring);
            SqlCommand    cmd  = new SqlCommand("UPDATE Person SET FirstName=@FirstName, LastName=@LastName, Age=@Age WHERE Id=@Id", conn);

            cmd.Parameters.AddWithValue("@Id", person.Id);
            cmd.Parameters.AddWithValue("@FirstName", person.FirstName);
            cmd.Parameters.AddWithValue("@LastName", person.LastName);
            cmd.Parameters.AddWithValue("@Age", person.Age);
            conn.Open();
            int rows = cmd.ExecuteNonQuery();

            conn.Close();
            if (rows > 0)
            {
                issuccess = true;
                return(issuccess);
            }
            return(issuccess);
        }