views:

687

answers:

3

I am using strongly-typed-dataset as an ORM to wrap around my Microsoft Access database, now I am looking for a way to create an equivalent of

UPDATE table1 SET table1.nationality = 'england'
WHERE table1.nationality in
(
 select table2.nationality from table2
 where table2.gender ='M'
);

in a strongly typed dataset designer, but not sure this is possible or not.

If this is not possible, what is the best way to accomplish this task? I am avoiding

  1. Hand-code SQL
  2. Store Proc

as much as I can.

Edit: I am not saying that hand-code SQL is not permissable, just that it's not desirable. The same goes for Store Proc

A: 

are you using a table adapter?

if so, can you not just right-click and choose Add Query, select new Select/Update/SQL statement, then enter

UPDATE table1 SET 
    table1.nationality = @nationality
WHERE table1.nationality in (
    select table2.nationality 
    from table2 
    where table2.gender = @gender
)

and give it an appropriate name? This should generate a table-adapter method like

updateNationalityByGender(string nationality, string gender)

you'll need to use the namespace for the table adapter to get access to it, e.g.

using your.name.space.datasetname.datasetnametableadapter;
Steven A. Lowe
I tried, but it didn't work
Ngu Soon Hui
@[Ngu Soon Hui]: what didn't work about it? this works fine on my machine - but i'm using SQL Server, not access...
Steven A. Lowe
@[Ngu Soon Hui]: and by the way, downvoting does not really encourage me to keep trying to help you ;-)
Steven A. Lowe
Sorry! I should have mentioned that @gender isn't working in Microsoft Access, and I am using Microsoft Access... apologies!
Ngu Soon Hui
@[Ngu Soon Hui]:my mistake, I was unaware that Access did not support the @parm syntax (I haven't used Access in many years); thanks to @[juliandewitt]: for clearing that up!
Steven A. Lowe
A: 

LINQ to DataSet would be your best option.

1) Its all strongly typed.
2) You can use IQueryable/LINQ/lambda to query
3) You can bind to an Access database

Sql Express is free and it would be much better to use that. But if i was forced to use Access, this is how i'd do it.

http://msdn.microsoft.com/en-us/library/bb386977.aspx

cottsak
+2  A: 

Like steven A low said.. but you use MS acces.. so params must be '?'

Right-click adapter and choose Add Query, select new Select/Update/SQL statement, then enter

UPDATE table1 SET 
    table1.nationality = ?
WHERE table1.nationality in (
    select table2.nationality 
    from table2 
    where table2.gender = ?
)

give it an appropriate name, ie. updateNationalityByGender

updateNationalityByGender(string nationality, string gender)
Julian de Wit