Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Excel - check whether data added to a SQL database

Posted on 2011-09-11
2
211 Views
Last Modified: 2012-05-12
Hi

In VBA I have written code to add data to an Access database.
I have code that checks the highest ID before and after the Insert Statement
and if this has changed returns a successful entry.
With multiple users however, this might cause problems.
Should I maybe also use a select statement to see if that exact info is there?
0
Comment
Question by:murbro
2 Comments
 
LVL 59

Accepted Solution

by:
Kevin Cross earned 500 total points
ID: 36518433
If you cannot use an alternative like method I showed with SCOPE_IDENTITY(), then you may need to do something like that to be absolutely certain. For example, you may check for MAX(ID) and 100, then execute an insert that fails, but check for MAX(ID) again which returns 101 as another process successfully inserted a new row. As an alternative, you could run a scalar query that tests EXISTS() or COUNT() ... WHERE based on your criteria; however, if the insert failed because there was already a row with your new data then this method may also be flawed.

You may have to use a stored procedure to do inserts where you can return true or false to indicate success or failure.
0
 

Author Closing Comment

by:murbro
ID: 36518880
Thanks very much
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

791 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question