473,513 Members | 2,425 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

There must be a faster way to dup check in Access than this...

11 New Member
Sorry if I posted in the wrong forum, but since I'm looking at VB code I have a 50/50 chance at being wrong. :)

I've been trying a variety of methods to speed up the checking for duplicates.

Right now I'm using a simple while statement and if statement to go through the database row by row checking the field I want, and then moving onto the next.

At the moment it works fine because the database is in its infancy, but I know down the line the database will have thousands of entries, and using this method will not be 'optimal' for when that time comes.

This is what I am doing to check the database for duplicate entries, and I KNOW there has to be a faster way. I cant imagine using this with a database with over 500,000 entries in it.

Expand|Select|Wrap|Line Numbers
  1.         Dim database_rows As Integer = 0
  2.         Dim current_row As Integer = 0
  3.         Dim noDup As Integer = 0
  4.         Try
  5.  
  6.             Dim CN As New OleDb.OleDbConnection
  7.  
  8.             CN.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Database\Jobs.accdb;Jet OLEDB:Database Password=123temp;"
  9.             CN.Open()
  10.  
  11.             Dim jb As String = "Select * From " & "JobBasics"
  12.             Dim da As New OleDb.OleDbDataAdapter(jb, CN)
  13.             Dim ds As New DataSet()
  14.             da.FillSchema(ds, SchemaType.Source, "JobBasics")
  15.             da.Fill(ds, "JobBasics")
  16.             database_rows = ds.Tables("JobBasics").Rows.Count
  17.  
  18.             'Check the database if the record already exsists
  19.             While (current_row < database_rows)
  20.                 If (g_v.JobBasics.jb_title = ds.Tables("JobBasics").Rows(current_row).Item("jb_title")) Then
  21.                     MsgBox("This job already exsists, please use the search function.", MsgBoxStyle.Exclamation, "Duplicate Entry!")
  22.                     CN.Close()
  23.                     Exit Sub
  24.                 Else
  25.                     current_row = current_row + 1
  26.                 End If
  27.             End While
  28.  
  29.  
  30.             'Add the Job Info to the database if the loop finds nothing
  31.             Dim cmdBuilder As New OleDb.OleDbCommandBuilder(da)
  32.             da.InsertCommand = cmdBuilder.GetInsertCommand
  33.  
  34.             With ds.Tables("JobBasics")
  35.  
  36.                 Dim dr As DataRow = .NewRow
  37.                 dr("jb_title") = g_v.JobBasics.jb_title
  38.                 dr("jb_id") = g_v.JobBasics.jb_id
  39.                 dr("jb_td") = g_v.JobBasics.jb_td
  40.                 dr("jb_ad") = g_v.JobBasics.jb_ad
  41.                 dr("jb_criteria") = g_v.JobBasics.jb_criteria
  42.                 dr("jb_description") = g_v.JobBasics.jb_description
  43.                 dr("jb_comments") = g_v.JobBasics.jb_comments
  44.                 dr("jb_lastdate") = g_v.JobBasics.jb_lastdate
  45.                 dr("jb_usr_id") = g_v.key.global_key(4)
  46.  
  47.                 .Rows.Add(dr)
  48.             End With
  49.             da.Update(ds, "JobBasics")
  50.             CN.Close()
  51.  
  52.         Catch ex As Exception
  53.             MsgBox(ex.Message)
  54.  
  55.         End Try
Anyone have some suggestions?
Mar 16 '08 #1
3 1413
debasisdas
8,127 Recognized Expert Expert
The best / fastest way to chek for duplicates is to use COUNT().

If it returns more than 1 there is duplicate entry.
Mar 17 '08 #2
Killer42
8,435 Recognized Expert Expert
I admit I haven't read your post in detail, only skimmed quickly.

But as for finding duplicates, keep in mind you may not need to. If the idea is to prevent creation of duplicates, then one simple method is to define a unique index on a field or combination of fields which will prevent it. In your code, you simply attempt to add your records, and trap the error that results if it is a duplicate.

Alternatively, rather than "manually" looping through the records you'd do better to use the power of the database by issuing a query to specifically find duplicates of the value(s) you're about to store.

A lot depends on the situation, obviously ("Know Thy Data" as usual). But in general, the former technique might be quicker if you expect duplicates to be rare, while the latter would be preferable if you expect to find duplicates most of the time.
Mar 17 '08 #3
Nimion
11 New Member
Thank you both, I was about to resond with 'how do I use the count()?" but openig up my SQL Server I found I was missing my ' and ' around my where item. :)

The reason I cant use a predefined index which auto counts up is because I'm using a randomly generated key of numbers and letters as the ID to track the job, as everything that has to do with the job is centered around the ID I thought it easiest to use that as my 'primary key'.

But the count way works perfectly :) for some reason when I was using it before, I kept using the Rows.count instead of the item(#).tostring! Which was my problem a week ago.

Thanks for the help! :)
Mar 18 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

7
1825
by: Arpan | last post by:
Microsoft, in one of its "Help & Support" pages on ADO, says that a System DSN is three times faster than a File DSN. I find that a bit odd for the simple reason that won't it be faster for a...
7
4076
by: Danny | last post by:
I am trying to process a database and my code does so much that it takes a whle to go through the database. most of it is sql queries, updates and such. For about 6000 records, it takes over a...
10
2162
by: Willem | last post by:
Looking for some opinions on alternatives to programming with Access. I find that quite often I need to loop through my recordsets (first to last) performing calculations and was wondering if...
24
1392
by: Sid | last post by:
Hi, I am writing an application where I look for a white pixel by testing if all the R,G,B values are 255 i.e. I use if(RGB == 255 && RGB == 255 && RGB == 255) (assuming RGB is a pointer to...
1
2703
by: James dean | last post by:
I done a test and i really do not know the reason why a jagged array who has the same number of elements as a multidimensional array is faster here is my test. I assign a value and do a small...
2
2488
by: Arjen | last post by:
Hello, How can I check the recordcount? Here is a little bit of my code: // Load first row into Datareader dr.Read(); if (dr.ToString() == "xmlsrc") {
11
2944
by: ctman770 | last post by:
Hi Everyone, Is it faster to save the precise location of an html dom node into a variable in js, or to use getElementById everytime you need to access the node? I want to make my application...
4
1754
by: shuisheng | last post by:
Dear all, Would you please tell me when using pointer and not using pointer, which is faster to access data? Such as float *pVal float val MyClass *pA pA->member1 MyClass a ...
16
5631
by: Brian Tkatch | last post by:
Is there a way to check the order in which SET INTEGRITY needs to be applied? This would be for a script with a dynamic list of TABLEs. B.
0
7166
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7386
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7543
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5689
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5094
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4749
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3236
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
805
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
459
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.