sql - How can I update/delete data on my table in C# using OOP? -
i'm done adding of data on table , works fine. i'm done coding update , delete function on class, it's not updating table. no errors found on program.
here's code:
public void studentupdate(string id, string lastname, string firstname, string middlename, string suffix, string age, string gender, string paddress, datetime birthday) { result.query = "update tbl_student set lastname = '" + lastname + "', firstname = '" + firstname + "', middlename = '" + middlename + "', suffix = '" + suffix + "', age = '" + age + "', gender = '" + gender + "', pmt_address = '" + paddress + "', birthday = to_date('" + string.format("{0:mm/dd/yyyy}", birthday.toshortdatestring()) + "','mm/dd/yyyy') std_id = '" + id + "'"; result.transaction = true; result.executenonquery(); studentcommit(); result.close(); } public void studentdelete(string id) { result.query = "delete tbl_student std_id = '" + id + "'"; result.executenonquery(); studentcommit(); result.close(); } public void studentcommit() { if (!result.commit()) { result.rollback(); } }
additionally, have created user login account creation code in table (update/delete function) working good. difference that, have 3 strings on login table while in student table have many strings plus 1 datetime.
most select part of update statement isn't locating records: http://weblogs.asp.net/stevewellens/why-sql-updates-fail-three-reasons
and, others pointed out, building strings doing makes code vulnerable sql injection. if it's internal application or homework, it's not big deal, otherwise should using parametrized queries.
Comments
Post a Comment