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 October 9th, 2009, 02:13 AM
Authorized User
 
Join Date: Sep 2009
Posts: 14
Thanks: 1
Thanked 0 Times in 0 Posts
Question AUTOINCREMENT IN SQL SERVER 2005??

db name:-mydatabase
table name:-login
coulms:-id(int,identityspecification-yes,identity increment=1,identity seed=1)
username(varchar 50, primarykey)
password(varchar 50)

now when I'm trying to insert, theres no problem if the record is not available.
but problem occurs when a record already exists.

id |username|password
1 | biswa | bitan
2 | hoity | toity
[now if I try to enter username=biswa and password=bitan
and the error handler produce an error message and stop
data insertion. if 2 attempts stopped by error handler. then
when I try for a new data, it looks like...]

5 | jack | jill

m really in problem....I need to increment the id when a valid insertion is done
please help me out....


thanks
__________________
Get the will power n U will be powered

Last edited by biswa; October 9th, 2009 at 02:16 AM..
 
Old October 9th, 2009, 03:28 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

So fix your code. Don't even *TRY* to do the INSERT if the record already exists.

Don't depend on the error handler. Write the code to do the check first.

A stored procedure would be the best way, but you could also just use ad hoc SQL.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Questions about SQL Server 2005 and SQL Server Express Edition 2005 gfmann BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 1 May 24th, 2009 09:36 AM
Difference between SQL Server 2000 and SQL Server 2005 leena K SQL Server 2005 4 March 31st, 2009 09:07 AM
reg conn to sql server 2005 from vb.net 2005.. veda SQL Server 2005 2 July 1st, 2008 12:16 AM
Conflict in SQL Server 2000 and SQL Server 2005 ayan.mukherjee SQL Language 0 June 30th, 2008 03:34 AM
AutoIncrement in Insert on SQL Server 2K CarlosV SQL Server 2000 5 January 19th, 2006 06:01 PM





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