Dan:
No… no data is loaded on the form at this point in the code and that why I was wondering initially…
From the originating post:
“Since nothing is being returned, I’m obviously missing something, or using the wrong method for this.”
My guess is that I’m totally using the wrong approach by thinking an EpiDataView is the correct tool to use. What I’m trying to do, specifically, is… as a new record is requested from the top menu, I want to look at the existing records in the UD11 table (this might get slightly confusing because I’m going to refer to fields that I didn’t use in my examples here in this post) and isolate the max value of “Key1”. Once that has been isolated, increment it by 1 and use that new value as the “Key1” value for the new UD11 record that was requested.
Basically, this is a simple effort to try and mimic creating a PKID for the UD11 table.
My line of thought was to do this during the “EpiViewNotification” event, when the notify type is “AddRow” (when a user requests a new record).
So, to reiterate, at this point, no data exists on the UD11 form. It’s a workflow of basically requesting a new record and at that point, kicking off custom code to look at what is currently existing in UD11, then grabbing the max value of “Key1”, then incrementing it and putting that new value into the “Key1” field for the data view of the open/new record.
Frustrated with the data view approach, I also tried to construct a SQL statement:
string strSQLQuery = "SELECT MAX(Ice.UD11.Key2)"
+ " FROM"
+ " Ice.UD11";
… and toss that into a data table object. Without the MAX statement, it’ll return the count of 3 rows that currently exist in the UD11 table. With the MAX statement, it’ll return a count of 1 row. All of that is expected - BUT - it will also behave exactly like the data view approach and return no values whatsoever.
I have also tried something like:
var varMaxNMR = (from row in Db.UD11 select row).LastOrDefault();
… but the compiler didn’t like the “Db” schema (nor did it like the “Ice” schema) and I didn’t know how to properly reference it. “LastOrDefault” was used here because what I need is the latest row in order to get the latest “Key1” value. In this manner, I didn’t exactly know how to replicate the MAX statement.
So, seems like I’m using the wrong tool for the job, however, I’ve tried two other methods and I’m not successfully piecing those together nicely either.
What might be your suggestion(s) here?