CodeCharge Studio
search Register Login  

Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> Archive -> GotoCode Archive

 Increment Previous record counter

Print topic Send  topic

Author Message
Karim
Posted: 09/17/2002, 8:17 AM

How can I grab the last record number and increment by one when I add a record?

Example, I have a field call seqnum and I want to increment the seqnum field by one when I add a new record to that row.

Thanks
Karim
imranz
Posted: 09/17/2002, 10:39 AM

Karim,

It looks like what you're trying to do is auto-increment a field in your table. This is something done by the database, not inside CodeCharge. For example, in Access, in the design view, you would set the datatype for your 'seqnum' field you mentioned to 'AutoNumber'. This is all you need. When you create a new record, the database would automatically add 1 to the number. By default, autonumber fields start with 1.

In MS SQL Server, you could set the 'seqnum' datatype to 'int', and in the Column properties, set 'Identity' to 'Yes' and make sure 'Identity Seed' and 'Identity Increment' is set to 1.

I don't know how this same thing works in MySQL, but I'm sure someone else here can help you with that if that is your preferred database...

Karim
Posted: 09/17/2002, 12:52 PM

Imranz,
You are right, if I wanted to increment sequentialy without any changes to the field, that works great.

But, I actually use the SEQNUM field in different ways, I do re-ordering of the field. If for example I have three records, ONE, TWO and THREE and in each record field SEQNUM I had 1,2 and 3, if I decided to move the numbers 2 to 1 in the SEQNUM field, that means I will have to update record ONE with SEQNUM 2 and record TWO with SEQNUM 1.

If I had the SQL auto increment on the field I don't think that will work? Will it?

I appriciate your input.

Thank you,
Karim
eDuck
Posted: 09/17/2002, 2:12 PM

first assign the seq number before displaying the page by getting the next seq number from the database. Then instead of inserting the record, just update the record since you now have the next seq returned to you. If the record did not get added, then simply issue a delete statment. You can also use the return value for SQL to return the rowid if it's an identity key if you want to use the after inesert approach.

Karim
Posted: 09/19/2002, 7:27 AM

eDuck,

What code would I use to grab the last record seqnum and then add one to it?

Thanks
Karim
eDuck
Posted: 09/19/2002, 8:52 AM

If you are using SQL, then simply create a stored proc that inserts a new record into your table. Create an output field as part of your stored proc which returns the @@ROWID (identity column) of your table:

IE:

DELCARE @NEXTID INT OUTPUT
...

INSERT INTO ...
..

SET @NEXTID = @@ROWID

Then you catch this value in your After Execute code section. It will return the value into a param in your CodeCharge, whatever you call it.

I hope this makes kind of sense.

   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Web Database

Join thousands of Web developers who build Web applications with minimal coding.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.