public void update <T>(T table) { string tableName = InfoClass.getClassName(table); StringBuilder sb = new StringBuilder("UPDATE " + tableName + " SET "); SqlParameter[] attributeNames = InfoClass.getPropertyNames(table); int tableLength = attributeNames.Length - 1; //We don't take the class id for (int i = 1; i < tableLength; i++) { sb.Append(attributeNames[i].ParameterName + "=" + "@" + attributeNames[i].ParameterName + ", "); } sb.Append(attributeNames[tableLength].ParameterName + "=" + "@" + attributeNames[tableLength].ParameterName); sb.Append(" WHERE " + attributeNames[0].ParameterName + "=" + attributeNames[0].Value); WriteInDatabase(sb.ToString(), attributeNames); }
public void insert <T>(T table) { string tableName = InfoClass.getClassName(table); StringBuilder sb = new StringBuilder("Insert into " + tableName); SqlParameter[] attributeNames = InfoClass.getPropertyNames(table); int tableLength = attributeNames.Length - 1; //column where we need to add values for (int i = 1; i < tableLength; i++) { sb.Append(attributeNames[i].ParameterName + ", "); } sb.Append(attributeNames[tableLength].ParameterName + ")"); //values of the columns sb.Append(" VALUES ("); for (int i = 1; i < tableLength; i++) { sb.Append("@" + attributeNames[i].ParameterName + ", "); } sb.Append("@" + attributeNames[tableLength].ParameterName + ")"); WriteInDatabase(sb.ToString(), attributeNames); }