lookup replaces field lookup (v2023)

Using ASPNM23
I’m using the standard code

public void Lookup_Selecting(DbField fld, ref string filter) {
    if (fld.Name == "MyLookupField") {
        fld.Lookup.UserSelect = "SELECT Field1 AS lf, Field2 AS df, Field3 AS df2, '' AS df3, '' AS df4 FROM Table1"; // Modify SELECT
        fld.Lookup.UserOrderBy = "Field2 ASC"; // Modify ORDER BY
    }
}

I’m trying to display additional fields in the lookup but save only the first two field in the table, but all four fields in my lookup get captured and overrides the field lookup,
How do I save only the first two fields even if lookup displays four fields.Thanks

Lookup should save the link field (lf) to the database only.

Thanks I’ve manged to get it to show only lf… when i save it shows in the view page… but now when I go back to edit page the record is empty and have to enter again.
both fiels are VarChar…

If you mean you want to show different value for lookup in view page, use the Row_Rendered server event.

no I mean that when you save the field the record shows in view… but when you then go back to edit the record disappears from the field, then have to re-enter the records. and then save again

You should simply:

I have checked the fields match the sequence of the fields in the lookup code match the fields in the aspnm field lookup table, i tried removing the fields, tried changing the link field, no matter what I do when i go back to the edit after a successful save, the records do not show and I have to re-enter.
Fields that do not use the code works and shows the old record.

You do not need the Lookup_Selecting codes. You should simply set up your lookup settings for use in the add/edit page and use the Row_Rendered server event to change the display value for the list/view page.

Row rendered seems to only modify css…

You can modify the field view value by:

Field.ViewValue = "<new value>";

Thanks but then there will still be a value… I just want to hide the last two display fields

You should get the row data and format on your own. For example:

var row = ExecuteRow("SELECT DisplayField1, DisplayField2 FROM LookupTable WHERE LinkField = ...");
Field.ViewValue = Convert.ToString(row["DisplayField1"]) + ", " + Convert.ToString(row["DisplayField2]);

When I go back to edit my record it’s empty.

Show you complete lookup settings and all the server event codes you are using.