Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB Databases Basics
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
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
Reply With Quote
  #2 (permalink)  
Old April 27th, 2005, 02:45 PM
Friend of Wrox
 
Join Date: Nov 2004
Location: Port Orchard, WA, USA.
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...)
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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



All times are GMT -4. The time now is 11:09 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.