Nick

Nick

  • NA
  • 1
  • 0

Trouble using a query as the basis for several other queries

Feb 16 2009 6:50 PM
I am building an application that will keep track of items.  Users will be allowed to insert data into an access database, and they will also be able to edit and return query results from this database.

Currently have brought in the oledb class, set up forms to enter information into the database.  Using oledbcommand and execute.nonquery I am able to enter the input into the database with no problem.  I am also able to write a query and display it in my datagridview.

My problem is this.  I need to query my db using user input, and then use these results to do further actions.  For example I would like to do something along these lines:

SELECT TOP "variable" field1, field2, field3
FROM table1
WHERE field3="A"

Up to here I'm fine, I can write this and make it work.  But, now I want to be able to use the results returned from above and do something like:

INSERT INTO table1(field4) VALUES ('S');
&
SELECT field1, field2, SUM(field3) AS SumOfField3
FROM table1
GROUP BY field2, field1 --> Again I want to use the results from the first query, and I also want to make SUM(field3)'s value available to the user.

Thanks for any help