Newbie code example question

  • Thread starter Thread starter John
  • Start date Start date
J

John

Hi

I need to copy records from table A to a new table B (overwrite if exists)
based on a flag field not set in table A. I then need to set flag for all
records in table A that are also in table B. How can I do this in ado.net
using vb.net?

Thanks

Regards
 
John said:
Hi

I need to copy records from table A to a new table B (overwrite if exists)
based on a flag field not set in table A
First, I'd use this http://www.knowdotnet.com/articles/datasetmerge.html to
copy the data from the first table to the second. If you are sure you want
Table A's data in B, I'd go ahead and do a Truncate Table (if you are in SQL
Server) or Delete * from Table B before INserting. This will give you all
of the records in A's query in Table B.

Now, you can just do one more commmand

Update TableA Set FlagField = FlagSet where SomeKeyValue in (SELECT KeyValue
from TableB)

Or, you could just use the same where clause in the Select statement you
used to fill the dataset with and use that where clause in your update
statement instead of the subquery. If you have values in B already and you
use the subquery, you'll set evreything in A that matches B to Flagged,
whereas if you use the same where clause then you'll only update the records
that you moved via the select statement.

Let me know if you have any questions.

Bill
.. I then need to set flag for all
records in table A that are also in table B. How can I do this in ado.net
using vb.net?

Thanks

Regards

--

W.G. Ryan, eMVP

http://forums.devbuzz.com/
http://www.knowdotnet.com/williamryan.html
http://www.msmvps.com/WilliamRyan/
 
Hi Bill

Thanks for that. Its just that I ma not too comfortable with ado.net syntax
and wondering which elements of ado.net should I use to carry out the sql
statements and how. The tables are ms access.

Thanks

Regards
 
John:

Which part specifically is giving you the trouble, filling it or the
checking if it's in the other table? Let me know and I'll gladly give you
soem code to walk through it. I think the link i sent you should get you
through the first part and the rowfilter will just need filled in for the
second but either way I'll get it for you if you can can tell me
specifically where you are having the problem.

--

W.G. Ryan, eMVP

http://forums.devbuzz.com/
http://www.knowdotnet.com/williamryan.html
http://www.msmvps.com/WilliamRyan/
 
Back
Top