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 7th, 2009, 03:27 PM
Authorized User
 
Join Date: Sep 2009
Posts: 14
Thanks: 1
Thanked 0 Times in 0 Posts
Question Stopping duplicate value insertion

Hi,

I'm in trouble to stop duplicate insertion in the database.
m using VB6.0 and Sql Server 2005.
How can I read the recordset ? is there any datareader , that I can compare whether the new value is already there or not?

Plz help me out.

Thanks.
__________________
Get the will power n U will be powered
 
Old October 8th, 2009, 04:22 AM
Authorized User
 
Join Date: Mar 2009
Posts: 49
Thanks: 0
Thanked 8 Times in 8 Posts
Default

strSQL = "SELECT COUNT(*) AS THECOUNT FROM sometable WHERE FieldOrFields = some criteria that you want to keep unique"
'open rs
If adoRs.Fields("THECOUNT") = 0 Then
'no records so add
Else
'record exists
End If



Good Luck
 
Old October 8th, 2009, 08:40 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Or you could just do:
Code:
strSQL = "SELECT 1 FROM sometable WHERE FieldOrFields = some criteria that you want to keep unique"
'open rs
If adoRs.EOF Then
    'no records so add
Else
    'record exists
End If





Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP & Forms: stopping spam and multiple posts stephen_c_ Beginning PHP 1 July 28th, 2005 02:36 PM
Duplicate Error Message Stopping it ru1 Access 2 February 25th, 2005 04:53 PM
Stopping frequent submission rajuru Beginning PHP 1 August 20th, 2004 09:56 AM
insertion sort..please amahja56 C++ Programming 1 March 1st, 2004 09:40 PM
ASP 0177 Object server is stopping when OLE servic not24 Classic ASP Components 2 August 12th, 2003 02:58 PM





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