How to get max value from a dataset column?

  • Thread starter Thread starter Steve Farmer
  • Start date Start date
S

Steve Farmer

Hi everybody,

I have a column in a DataSet (ItemNo) where I need to find out the
highest number, so I can add 1 to it when a new record is written to the
database. What is the best way to that please?

Steve
 
Steve, a DataSet is a collection of one of more tables, so technically what
you need is the max of a datacolumn. You can use the Compute method
something like this

Dim i As Integer =
CType(AllData.Tbl_Job_Tracking.Compute("MAX(Line_Count_1)", "Line_Count_1
=0"), Integer)



Or you can just use an Expression column that computes max.

More importantly, if you are using an autoincrement field,, don't do it
using this method. Set the AutoIncrement property on the data column to
true, set the seed to 0 and then set the step to -1. That way the DB will
take care o finserting identity fields for you and you won't have to worry
about a clash if your app goes multi-user.



HTH,



Bill
 
Back
Top