Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB Databases Basics
|
VB Databases Basics Beginning-level VB coding questions specific to using VB with databases. Issues not specific to database use will be redirected to other forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB Databases Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 27th, 2005, 07:54 AM
vbmazza
Guest
 
Posts: n/a
Default Inserting a Value into an SQL Identity Field in VB

I am using Visual Basic .Net to insert values into an SQL Database.

One of the fields I have is an Identity Field, the purpose of this field in my database is to have a number that increments by 1 each time a record is entered.

The problem is that I don't know what value to use in my INSERT INTO command to do this. Because I am new to this, my understanding of the Identity field was that it automatically incremented the value in that field each time a new record was inserted, if this is not the case can someone help me with this.

Basically I have a field called ReportID, I am inserting a date and a name into this database and I want it to auto-generate the ReportID number to increment by 1 each time a record is entered. Bearing in mind the each value is stored in a string or date variable.

I am pulling my hair out, so any help would be great!

VBMazza
 
Old April 27th, 2005, 02:45 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Your database should be set up so that there is a trigger before insertion. That trigger should get the next value from a sequence that has been set up for this table. When the value is retrieved fram a sequence, the sequence is automatically incremented.

The Before Insert trigger should fill in the value.

(BTW: the trigger should do all of this only if the record is a new record...)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Inserting data using VB.net and sql express saif44 Visual Basic 2005 Basics 6 June 18th, 2007 08:23 PM
inserting XML/ASCII data into SQL using VB.net outcast1881 Other Programming Languages 0 July 20th, 2006 07:39 AM
Inserting data into an Access memo field with SQL jhunta VB How-To 3 September 20th, 2005 02:49 PM
getting identity field chanceeve Classic ASP Databases 2 June 5th, 2004 01:31 AM
SQL Server Identity field won't increment Ron Howerton VB.NET 2002/2003 Basics 8 April 22nd, 2004 12:14 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.