Looping through records

westerncj

New member
Joined
Feb 9, 2012
Messages
3
Programming Experience
Beginner
I'm new to programming with VB.net. I'm using Stored Procedures to select all records from a table on a different server to a local table. I also have INSERT, UPDATE and an Exist Stored Procedure that will check to see if an AssetID already exists on my local table. If it already exists it won't insert the record. (Basically trying to make sure the local table is up to date with the one on another server). I created my .dll's.

How would call the first select statment then insert into another table according to whether or not it exists? I know I need to use a loop to go through each record to see if that AssetID already exists. How would I code that? I've been looking for examples.

I attached my Stored Procedures to this post.


Can anyone help?
 

Attachments

  • FASTrackingHeaderInsert.zip
    4.3 KB · Views: 27
Your best option would be to write a so-called UPSERT procedure. You simply pass a record to that procedure and it does the rest, i.e. checks whether the record already exists and then either UPdates or inSERTs, depending on the result. You then don't have to do any thinking in your application. You just pass all the data to the database and it does the rest.
 
Back
Top