?
Solved

Best way to skip duplicate records when updateng table in vb.net and sql

Posted on 2015-01-23
3
Medium Priority
?
173 Views
Last Modified: 2015-02-24
Hi I have a table made up like
machineID
UserNumber
VMode
IMode
CDateTime
WCode
ValidEntry

there are 3 fields that make the unique key which are
machineID
UserNumber
CDateTime

most times there are about 3000-5000 logs to download and I put these into a table. I used to fill the table first before trying the insert in a try catch block so that is would not add duplicates but takes too long. So then thought lets just get the data and fill a table then update the database. It downloads all the logs in seconds but having trouble when trying to use the tableadapter to save it.

this is what I was using
INSERT INTO CLog
                         (machineID, UserNumber, VMode , IMode , CDateTime, WorkCode, ValidEntry)
SELECT        @machineID AS Expr1, @UserNumber AS Expr2, @VMode AS Expr3, @IMode AS Expr4, @CDateTime AS Expr5, @WCode AS Expr6, @ValidEntry AS Expr8
WHERE        (NOT EXISTS
                             (SELECT        machineID, UserNumber, CDateTime
                               FROM            ClockInLog AS ClockInLog_1
                               WHERE        (machineID= @machineID) AND (UserNumber= @UserNumber) AND (CDateTime= @CDateTime)))

Open in new window



when the table adapter tries to do the update I get the error
The parameterized query '(@machineIDvarchar(1024),@UserNumber varchar(1024),@VMode' expects the parameter '@machineID, which was not supplied.

I don't get why I am getting this error if I try it in the dataset query editor it works fine.

And does vb.net build a big query and send it in one go or open the connection and loop through the insert statements?
0
Comment
Question by:taz8020
[X]
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
3 Comments
 
LVL 18

Accepted Solution

by:
Simon earned 2000 total points
ID: 40567009
An INSERT statement does it all in one go (set based).

I'm not sure why it doesn't work for you. It might be that you need to wrap all varchar values with single quotes
e.g.
SELECT        CHAR(39)+@machineID +CHAR(39), CHAR(39)+@UserNumber+CHAR(39), @VMode, @IMode, @CDateTime, @WCode, @ValidEntry

I'm not sure what datatypes all your other columns are, so I've only added CHAR(39) =single quote around the first couple.
0
 
LVL 49

Expert Comment

by:Martin Liss
ID: 40627754
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month13 days, 17 hours left to enroll

801 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