Click here to Skip to main content
15,895,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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

1 solution

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.
 
Share this answer
 
Comments
Jitendra sondarva 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900