Best way to read two columns in a row?

Gladimir

Well-known member
Joined
Mar 29, 2003
Messages
60
Location
San Diego, CA
I have a table whose sole purpose is to store the last masterID and lastTempID numbers used in other tables. So, the table only has a single row of data two columns wide. The first column holds the lastMasterID and the second column holds the lastTempID.

The application contains various functions that process hundreds of thousands of rows of input tables. These functions might need to get and set the lastMasterID or the lastTempID depending on whether or not new data is found in the input tables.

What is the best / slickest way to setting this up?

I was simple making two public functions called getlastMasterID and getlastTempID that returns the value of the corresponding field.

However, I think a public class that allows me to get and set in the same function might be more efficient (if I am using the correct terminology).

Either way, do I simply create the necessary connection and adapter objects and populate a dataset using the adapters Fill method? Or is that way too much overhead for what I need to do?
 
I would use a DataReader for this, if you really need to know the IDs in your client application. Youll definitely want to use one SQL statement (a Query in Access or a Stored Proc in SQL Server) to handle both the UPDATE and SELECT, as youll want to guarantee that you get a unique value.

Generally, you dont really need these IDs until youre ready to save, not just when the user clicks a new "New Row" button. Its generally better to not increment your identity values until you actually do an insert. That means you may not even need a class to handle getting an ID - instead, the proc thats going to do an INSERT using a Master or TempID will do the necessary SQL code to UPDATE the master ID table and get the current value.

-Nerseus
 
Back
Top