Make a Select command from two tables

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Can i do this is ADO.NET using C# and a SQL server.

Select * from table1
where Client= ( //What i want is (Client=CodCli)
select CodCli, Vend from Table2
Where Vend ='Variable';

From i read i cant make a dataset from diferent tables, so how would you
solve this problem.
 
strSQL = "select A.* from Table1 A
join Table2 B on B.CodCli = A.Client
where B.Vend = " & strVar
 
Jeff Dillon said:
strSQL = "select A.* from Table1 A
join Table2 B on B.CodCli = A.Client
where B.Vend = " & strVar

Just take note that a select constructed in this way is prone to sql
injection attacks.
Instead concatenating string, you should use parametrised queries.
 
I make a "small" error.
what e mean is: Select command from two tables in diferente SQL server
Databases.
How to create a dataadapter to do this?
 
Use SQL Server Linked Tables. Then you can refer to the remote table using 4
part naming in a single SELECT statement.

And agreed on the previous post regarding SQL Injection.

Jeff
 
Back
Top