468,513 Members | 1,750 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,513 developers. It's quick & easy.

How to get max value from a dataset column?

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

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #1
1 10125
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_C ount_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

"Steve Farmer" <sfarmer@flintind-remove-.com> wrote in message
news:ur**************@TK2MSFTNGP12.phx.gbl... 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

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Mike Gage | last post: by
3 posts views Thread by ALPO | last post: by
3 posts views Thread by Chris | last post: by
4 posts views Thread by Hardy Wang | last post: by
7 posts views Thread by Peter | last post: by
8 posts views Thread by Leon_Amirreza | last post: by
3 posts views Thread by =?Utf-8?B?UmljaCBIdXRjaGlucw==?= | last post: by
reply views Thread by NPC403 | last post: by
1 post views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.