MAX MIN functions

Sep 24, 2010 at 8:49 AM

Hi,

is there a way to use Max/Min functions within the DB? For example:

I have a table with 2 fields: ID (int), Name (string)

I have to insert a new item in a table and I need to know the max ID in the table, so I can insert the new item with a ID greater than the max value already present.

 

thanks,

Sep 30, 2010 at 9:15 PM

Did you figure this out?  If so, please let us know, otherwise try using GUIDs instead.

Generate a new guid for the id when you create and insert the record.  Use GUID as the datatype if it supports it or use a string and convert the guid to a string?

Coordinator
Oct 1, 2010 at 1:27 AM

This should be pretty easy with Linq.  Make sure to add using System.Linq to your code file.

Then you can do something like

if (db.Table<Thing>().COunt()>0)

{

return (from one in db.Table<Thing>() select one.ID).Max()

}

else

{

return 1;

}