Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
I have been developing application using VB.NET and SQL Server 2005. There is one software is already been developed and in running mode, now I have to develop facility that user can add one record on that software and same record will add into my database table also.
 
For that I have to write some code for when I will open particular screen / page in my application it will check the database table on said software/application and found if any new entry/record than it will appear in my application screen also, in other words it will retrieve data from said software's Database and save into my application database.
 
In short I have to import record for database table from one database to another database using VB.NET code.
 
Please advice.
 
Anyone can please help me on this??
Posted 21-Nov-12 2:36am

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi,
 
You should use SQL Trigger functionality for this, by using Trigger you should get this easily. For this you have to write one Insert Trigger on your
First DB (Destination DB - Existing software DB). When record insert on particular table in (Destination DB - Existing software DB)'s table it will automatically
insert into you Source DB particular table using Trigger.
 
Review below sample SQL code for
 
CREATE TRIGGER another_db_insert ON test_table FOR INSERT
AS
BEGIN
BEGIN TRANSACTION test_insert
 
-- Destination Database Test_Destination_DB
INSERT INTO Test_Destination_DB.dbo.destination_table(Id, Name)
SELECT Id, Name FROM inserted AS Source_table
 
IF (@@ERROR != 0)
BEGIN
ROLLBACK TRANSACTION test_insert
RETURN 0
END
ELSE
BEGIN
COMMIT TRANSACTION test_insert
RETURN 1
END
END
 
Hope this will works for you! Good luck
 
NOTE: This will works if both databases are on same SQL server.
  Permalink  
Comments
Jitendra sondarva at 22-Nov-12 23:26pm
   
Yeah.. Thanks Raj Acharya!
 
I have tried your solution and create one test environment. Its works.. Cheers!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 240
1 Kamal Rocks 184
2 BillWoodruff 173
3 PIEBALDconsult 160
4 CPallini 155
0 OriginalGriff 5,695
1 DamithSL 4,506
2 Maciej Los 4,007
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,180


Advertise | Privacy | Mobile
Web04 | 2.8.141216.1 | Last Updated 22 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100