Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Auto-Numbering
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Auto-Numbering

 Post Reply Post Reply Page  <123>
Author
Bunce View Drop Down
Senior Member
Senior Member
Avatar

Joined: 10 April 2002
Location: Australia
Status: Offline
Points: 846
Post Options Post Options   Thanks (0) Thanks(0)   Quote Bunce Quote  Post ReplyReply Direct Link To This Post Posted: 02 July 2003 at 9:36pm

What error message are you getting?
What code are you using to add a record to the database?

Remember you should not include the name of the Identity field in you code when adding the new record.

Cheers,
Andrew

There have been many, many posts made throughout the world...
This was one of them.
Back to Top
Awangku View Drop Down
Groupie
Groupie


Joined: 15 November 2001
Location: Malaysia
Status: Offline
Points: 70
Post Options Post Options   Thanks (0) Thanks(0)   Quote Awangku Quote  Post ReplyReply Direct Link To This Post Posted: 03 July 2003 at 6:58pm

I got the "HTTP 500 - Internal server error" message. And these are the codes I use to add new records in my table.

Set rsProcess = Server.CreateObject("ADODB.Recordset")
rsProcess.CursorType = 2
rsProcess.LockType = 3
rsProcess.Open strSQL, strCon

rsProcess.AddNew
rsProcess.Fields("Test1").value = strTest1
rsProcess.Fields("Test2").value = strTest2
rsProcess.Fields("Test3").value = strTest3
rsProcess.Update
rsProcess.Requery
rsProcess.MoveLast

rsProcess.Close
Set rsProcess = Nothing

I set the first column in my table as Identity, without modifying its settings.

Back to Top
Bunce View Drop Down
Senior Member
Senior Member
Avatar

Joined: 10 April 2002
Location: Australia
Status: Offline
Points: 846
Post Options Post Options   Thanks (0) Thanks(0)   Quote Bunce Quote  Post ReplyReply Direct Link To This Post Posted: 03 July 2003 at 10:20pm

Firstly, you don't need to open a recordset if you're not going to be displaying it on the page.

Secondly, if you're Identity column is [Test1], then you shouldn't be addding anything to that column as the database will do it for you. It therefore, should not be in your code.

So, code to create a new record:

dim strSQL as string
strSQL = "INSERT INTO [MyTable] ([Field1],[Field2],[Field3]) VALUES ('Value1','Value2','Value3')
myConn.execute(strSQL)

Note, field1, field2 and field3 are not identity fields.  The identity field is called something else, that you don't need to mention in your code. Value1, value2 and value3 are surrounded by quotes when strings, otherwise they should be left off for numerical fields.

myConn is a connection that you have already established in your code.

Cheers,
Andrew



Edited by Bunce
There have been many, many posts made throughout the world...
This was one of them.
Back to Top
Awangku View Drop Down
Groupie
Groupie


Joined: 15 November 2001
Location: Malaysia
Status: Offline
Points: 70
Post Options Post Options   Thanks (0) Thanks(0)   Quote Awangku Quote  Post ReplyReply Direct Link To This Post Posted: 04 July 2003 at 1:29am

I'll give that a try. Thank you. You've been a great help.

One question, though.

Let's say that I've got that identity thing up and running. What would happen if I delete some of the records already in the table? Would there be gaps in the identity numbers? (I'm still in the development phase, so I can do whatever I like to the database.)

Back to Top
Bunce View Drop Down
Senior Member
Senior Member
Avatar

Joined: 10 April 2002
Location: Australia
Status: Offline
Points: 846
Post Options Post Options   Thanks (0) Thanks(0)   Quote Bunce Quote  Post ReplyReply Direct Link To This Post Posted: 04 July 2003 at 7:56am

There will (and should) be gaps in the autonumber if that happens.

Try to think of Autonumber (primary key) fields' purpose, purely to uniquely identify records and to be used in relationships between tables. 

They should rarely (if ever) be seen by anyone except the database developer.

For simplicity, take for example a table of customers and a table of Purchases. 

Customer (Ralph) with an ID (Autonumber) of 10 has been part of a dozen or so purchases.  Therefore Ralph's Customer ID (10) is in the Purchases table 10 times, alongside the relevant product.

Now Ralph leaves. His record gets deleted from the customers table.  A new customer (Bill) comes along and gets Ralphs old ID of 10, which is now free... Whoops! Ralph has automatically made 10 puchases since he is linked to those 10 puchases in the Purchases table.

This is why the autonumber or identity field numbers are not recycled.

And if everyone understands that they should not be used or shown publicly for identifcation then there wouldn't be any problems.

Hope this helps,
Andrew

There have been many, many posts made throughout the world...
This was one of them.
Back to Top
ljamal View Drop Down
Mod Builder Group
Mod Builder Group


Joined: 16 April 2003
Status: Offline
Points: 888
Post Options Post Options   Thanks (0) Thanks(0)   Quote ljamal Quote  Post ReplyReply Direct Link To This Post Posted: 04 July 2003 at 8:52am
With a good DB design, if a record is deleting all references to that should be deleted as well so that there are no orphaned records in other tables.
Back to Top
Bunce View Drop Down
Senior Member
Senior Member
Avatar

Joined: 10 April 2002
Location: Australia
Status: Offline
Points: 846
Post Options Post Options   Thanks (0) Thanks(0)   Quote Bunce Quote  Post ReplyReply Direct Link To This Post Posted: 04 July 2003 at 9:43am

That goes without saying. 

Was the easiest way to provide an example.

In the above situation, the customers record shouldn't be deleted in the first place.

There have been many, many posts made throughout the world...
This was one of them.
Back to Top
Awangku View Drop Down
Groupie
Groupie


Joined: 15 November 2001
Location: Malaysia
Status: Offline
Points: 70
Post Options Post Options   Thanks (0) Thanks(0)   Quote Awangku Quote  Post ReplyReply Direct Link To This Post Posted: 06 July 2003 at 7:01pm

Yup.. that helps a lot. It also means I can't use identity in all of my tables since there'll be quite a number of deleting and adding new records to the tables once the whole project goes live.

Thanks Andrew. You've been a great help.

 

Back to Top
 Post Reply Post Reply Page  <123>

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.