473,385 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 10450
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Andreas Palm | last post by:
I have a dataset that has DBNull in certain columns, now when I write out this one to XML, I only get the columns as elements that do have data in it. However I do need also the empty colums as...
2
by: Mike Gage | last post by:
I am trying to populate DataSets with results from SQL queries. Usually, to that end, the DataSet.Fill method works fine. If however the table includes a character field populated with a space,...
3
by: ALPO | last post by:
We have a datagrid built using template columns. Many are text boxes. These text boxes are bound to a datasource as follows: <ItemTemplate> <asp:TextBox id="txtPeriod1" runat="server"...
3
by: Chris | last post by:
I have a dataset that I want to modify the values in a particular column. I.e if I have a function to convert the enterbyID (Integer) to a name, in the dataset the field (Concern_EnteredbyID) shows...
4
by: Hardy Wang | last post by:
Hi all, I have following code to read Excel content into a DataSet string connection = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileName + ";Extended Properties=\"Excel...
7
by: Peter | last post by:
Gday, I have a dataset with multiple tables, from which I want to access a single value in one of those tables. I know I can do something like: Decimal myVar =...
9
by: PeterWellington | last post by:
I have a column in a data table that stores enum values and assigns a default value: Dim dc As New DataColumn("TestEnumField", GetType(DayOfWeek)) dc.DefaultValue = DayOfWeek.Thursday When I...
8
by: Leon_Amirreza | last post by:
I have a column named "ID" and its type is "uniqueidentifier" in SQL Server 2005 Express. this column is the primary key and its default value is "newid()" in SQL Server. I have generated a...
3
by: =?Utf-8?B?UmljaCBIdXRjaGlucw==?= | last post by:
I'm not really sure how to ask this question because I'm still getting my feet wet with data access and VB.NET, but here goes: To start off with, I'm using VB 2005 Express to connect to an Access...
0
by: kasukur | last post by:
Hi what i was trying to do is, i am using Dataset to populate data and update the database. The problem is i have a column which is of type Varchar(1), doesn't accept Nulls and default value is 0...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.