public bool DeleteEntity(AbDatabaseEntity Entity) { //Initial connection maker to make a connention SQLServerConnMaker SQLconn = new SQLServerConnMaker(); //Initial UserRecord entity UserRecord userRecord = (UserRecord)Entity; // Delete record from UserRecordCategories table SqlCommand deleteUserCategoryCmd; deleteUserCategoryCmd = new SqlCommand("DELETE FROM UserRecordCategories WHERE RecordID = @RecordID;", SQLconn.Connect()); // Add the parameters for the DeleteCommand. deleteUserCategoryCmd.Parameters.AddWithValue("@RecordID", userRecord.RecordID); try { SQLconn.Connect().Open(); using (deleteUserCategoryCmd) { deleteUserCategoryCmd.ExecuteNonQuery(); } } catch (Exception e) { //show error in output Console.WriteLine(e.ToString()); } finally { SQLconn.Connect().Close(); } throw new NotImplementedException(); }
public bool EditEntity(AbDatabaseEntity Entity) { //Initial connection maker to make a connention SQLServerConnMaker SQLconn = new SQLServerConnMaker(); //Initial UserRecord entity UserRecord userRecord = (UserRecord)Entity; // Create the DeleteCommand. // Delete record from UserRecord table SqlCommand editUserRecordCmd; editUserRecordCmd = new SqlCommand(@"UPDATE UserRecord SET UserName= @Username, UserPassword= @Password, Note= @Notes WHERE RecordID= @RecordID;", SQLconn.Connect()); // Add the parameters for the DeleteCommand. editUserRecordCmd.Parameters.AddWithValue("@RecordID", userRecord.RecordID); editUserRecordCmd.Parameters.AddWithValue("@Username", userRecord.UserName); editUserRecordCmd.Parameters.AddWithValue("@Password", userRecord.UserPassword); editUserRecordCmd.Parameters.AddWithValue("@Notes", userRecord.Note); editUserRecordCmd.Parameters.AddWithValue("@RecordID", userRecord.RecordID); try { SQLconn.Connect().Open(); using (editUserRecordCmd) { editUserRecordCmd.ExecuteNonQuery(); } } catch (Exception e) { //show error in output Console.WriteLine(e.ToString()); } finally { SQLconn.Connect().Close(); } throw new NotImplementedException(); }
public bool SaveEntity(AbDatabaseEntity Entity) { //start the connection string SQLServerConnMaker SQLconn = new SQLServerConnMaker(); //initialize user record values UserRecord userRecord = (UserRecord)Entity; //initialize user record category UserRecordCategory userRecordCategory = (UserRecordCategory)Entity; //create the SQL command to add user input SqlCommand addUserRecord; try { SQLconn.Connect().Open(); //calling methods to demonstrate sqlCommand capabilities addUserRecord = new SqlCommand("dbo.AddRecord", SQLconn.Connect()); addUserRecord.CommandType = CommandType.StoredProcedure; //addUserRecord.Parameters.Add("@categoryName", SqlDbType.VarChar).Value = addUserRecord.Parameters.Add("@id", SqlDbType.VarChar).Value = userRecord.UserName; addUserRecord.Parameters.Add("@pw", SqlDbType.VarChar).Value = userRecord.UserPassword; addUserRecord.Parameters.Add("@note", SqlDbType.VarChar).Value = userRecord.Note; addUserRecord.ExecuteNonQuery(); } catch (Exception e) { //show error in output Console.WriteLine(e.ToString()); } finally { SQLconn.Connect().Close(); } throw new NotImplementedException(); }