SaraniO SaraniO - 3 months ago 7
C# Question

How to Select from 2 table in one OleDbDataAdaptercommand in C#

I have a

database
in access 2013, and I want to select from 2 of it's tabale in one command,
this is my try:

OleDbDataAdapter DataA = new OleDbDataAdapter(@"Select FeedName from tFeeds where FeedID IN (Select FeedID from tFeedsRations),
FeedQuantity from tFeedsRations", Connection);
DataTable DTable = new DataTable();
DataA.Fill(DTable);


but it gives:


syntax error (comma) in query expression 'FeedID IN (Select FeedID from tFeedsRations)


is it possible to do smoething like that at all?

Answer

Select FeedName from tFeeds where FeedID IN (Select FeedID from tFeedsRations), FeedQuantity from tFeedsRationsis not valid SQL.

It looks like you're trying to perform a join, which would be does as follows.

SELECT tf.FeedName, tfr.FeedQuanity FROM tFeeds AS tf INNER JOIN tFeedsRations AS tfr ON (tf.FeedID = tfr.FeedID)