Question link 2 tables

arv_rehal

New member
Joined
Jun 15, 2009
Messages
2
Programming Experience
Beginner
Hi All,

I have two tables in SQL Server 2005 with name table1 and table 2, both is having same fields name,phone, email and few common records too. Email is a primary key. Now I want to shift the data from table 2 to table 1. but I want that in a form(using VB.net) it display the information of both tables record by record. If i found that information in any field of second table is latest then i will select that if information in 1st table field is latest then i will select that. whatever field I select for that particular record it should store that in table 1.

Can anyone help me to do this.

Thanks
 
How do you define "latest" ?

Here's a trick:
First read the DW2 link in my sig, and understand how to get data into a grid on a form
Do a tableadapter for the query:
VB.NET:
Expand Collapse Copy
SELECT
  email as t2email,
  name as t2name,
 ...
FROM
  table2
Save the dataset
Now modify the selection query to:

VB.NET:
Expand Collapse Copy
[code]
SELECT
  t1.email as t2email,
  t1.name as t2name,
 ...
  t2.email as t2email,
  t2.name as t2name,
 ...
FROM
  table1 t1
  FULL OUTER JOIN
  table2 t2
  ON
    t1.email = t2.email

The dataset wizard asks if you want to modiify your updating commands. Say no
Now manually edit the INSERT command, and change it from INSERT INTO table2 to INSERT INTO table1

Now you have a dataset that has a join grid view, and an insert command that targets table1 and a parameters collection that gets its data from table2

Drag the grid to the form
Set up a context menu with an item "Add to Table1"
The click handler should get the underlying row currently highlighted in the grid and call SetAdded() on it
Then you should, in a save button, call tableadapter.Update() on the datatable


If all this seems complex, the simpler way is:

Create 2 tableadapters, one for table 1 and one for the joined 1&2
Show the joined grid on screen, but when you click the context menu item, just call table1tableadapter.Insert(...) the list of values from the grid
 
Back
Top