473,414 Members | 1,598 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

how to pass the result of one query in other query in vb.net

111 100+
Hii all,

i have 2 queries, query1 and query 2

Query1 is selecting from results of Query2... is it possible???

Can somebody provide with code snippets in VB.NET to call such queries.


thnx..
Jul 12 '07 #1
6 1490
radcaesar
759 Expert 512MB
Its not vb.net its general SQL Sub query

SELECT * FROM employees
WHERE id =
(SELECT EmployeeID FROM invoices WHERE EmployeeID='E0006');
Jul 12 '07 #2
rhepsi
111 100+
Its not vb.net its general SQL Sub query

SELECT * FROM employees
WHERE id =
(SELECT EmployeeID FROM invoices WHERE EmployeeID='E0006');

thnx,..
i wud be more grateful if u can solve my queries

query 1)

Dim myselectquery As String = "SELECT pr_project_id_pk FROM tbl_projects WHERE tbl_projects.pr_project_location = ?PName "

cmSQL.Parameters.Add("?PName", objListItem)

query 2)

Dim myselectquerya As String = "SELECT sta_category_id_fk FROM tbl_staff_assignments WHERE tbl_staff_assignments.sta_project_id_fk =<<i need the result of query 1>> tbl_projects.pr_project_id_pk = ?CID "

cmSQL.Parameters.Add("?CID", 1)

thnx ...
Jul 12 '07 #3
Vidhura
99
thnx,..
i wud be more grateful if u can solve my queries

query 1)

Dim myselectquery As String = "SELECT pr_project_id_pk FROM tbl_projects WHERE tbl_projects.pr_project_location = ?PName "

cmSQL.Parameters.Add("?PName", objListItem)

query 2)

Dim myselectquerya As String = "SELECT sta_category_id_fk FROM tbl_staff_assignments WHERE tbl_staff_assignments.sta_project_id_fk =<<i need the result of query 1>> tbl_projects.pr_project_id_pk = ?CID "

cmSQL.Parameters.Add("?CID", 1)

thnx ...
Dim myselectquerya As String = "SELECT sta_category_id_fk FROM tbl_staff_assignments WHERE tbl_staff_assignments.sta_project_id_fk =(SELECT pr_project_id_pk FROM tbl_projects WHERE tbl_projects.pr_project_location = ?PName ) and tbl_projects.pr_project_id_pk = ?CID "
Jul 12 '07 #4
thnx,..
i wud be more grateful if u can solve my queries

query 1)

Dim myselectquery As String = "SELECT pr_project_id_pk FROM tbl_projects WHERE tbl_projects.pr_project_location = ?PName "

cmSQL.Parameters.Add("?PName", objListItem)

query 2)

Dim myselectquerya As String = "SELECT sta_category_id_fk FROM tbl_staff_assignments WHERE tbl_staff_assignments.sta_project_id_fk =<<i need the result of query 1>> tbl_projects.pr_project_id_pk = ?CID "

cmSQL.Parameters.Add("?CID", 1)

thnx ...
query 2)

Dim myselectquerya As String = "SELECT sta_category_id_fk FROM tbl_staff_assignments WHERE tbl_staff_assignments.sta_project_id_fk =(SELECT pr_project_id_pk FROM tbl_projects WHERE tbl_projects.pr_project_location = ?PName ) tbl_projects.pr_project_id_pk = ?CID "

cmSQL.Parameters.Add("?PName", objListItem)
cmSQL.Parameters.Add("?CID", 1)

hope this helps you.
Jul 12 '07 #5
rhepsi
111 100+
query 2)

Dim myselectquerya As String = "SELECT sta_category_id_fk FROM tbl_staff_assignments WHERE tbl_staff_assignments.sta_project_id_fk =(SELECT pr_project_id_pk FROM tbl_projects WHERE tbl_projects.pr_project_location = ?PName ) tbl_projects.pr_project_id_pk = ?CID "

cmSQL.Parameters.Add("?PName", objListItem)
cmSQL.Parameters.Add("?CID", 1)

hope this helps you.

thnx so much tht helped me....

i have other doubr nw....



Try
cnSQL.Open()
drSQL = cmSQL.ExecuteReader()

If drSQL.HasRows = True Then

While drSQL.Read

If drSQL.Item("sta_category_id_fk ") = "?CID" Then

MsgBox("Manager available in this project.. select other project or insert new project")
Else
insert record


my doubt is near ( If drSQL.Item("sta_category_id_fk ") = "?CID" Then )


is this right??? im not getting the result..

plz help..
thnx
Jul 12 '07 #6
thnx so much tht helped me....

i have other doubr nw....



Try
cnSQL.Open()
drSQL = cmSQL.ExecuteReader()

If drSQL.HasRows = True Then

While drSQL.Read

If drSQL.Item("sta_category_id_fk ") = "?CID" Then

MsgBox("Manager available in this project.. select other project or insert new project")
Else
insert record


my doubt is near ( If drSQL.Item("sta_category_id_fk ") = "?CID" Then )


is this right??? im not getting the result..

plz help..
thnx
hi,

here you are using a datareader and can not use "?CID", you can directly compare it with the value like:
If drSQL.Item("sta_category_id_fk ") = CID Then
Jul 13 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

13
by: dogu | last post by:
Noob alert. Code is below. File is saved as a .php. What I'm trying to do: User uses 'select' box drop down list to pick a value. Value ($site) is derived from a db query. This works fine....
6
by: HH | last post by:
I'm learning to design web applications with php, mysql, and apache from a book. I copied a sample application called guestbook 2000 that came with the CD in the book to my htdocs folder, but...
4
by: Corey | last post by:
All, I am relatively new to XML and I have what may sound like a dumb question. I want to pass a query string variable to my xml document and filter the output based on that variable. For...
3
by: Mark Horton | last post by:
I thought would be a super simple project, but I was wrong. I need Help!!!! I am using the Word.Application.Mailmerge.OpenDataSource to try and send a Dynamic Query to my stated Document.Open...
3
by: Zlatko Matić | last post by:
Hello. I'm wondernig what is happennig whith saved pass-through queries nested in regular JET query if regular JET query just filtrates result by start/end date...Does pass-through query first...
9
by: Alan Silver | last post by:
Hello, I'm a bit surprised at the amount of boilerplate code required to do standard data access in .NET and was looking for a way to improve matters. In Classic ASP, I used to have a common...
7
by: Bernard Lebel | last post by:
Hello, I'm stumbled at a serious problem, and quite frankly getting desparate. This is a rather long-winded one so I'll try to get straight to the point. I have this Python program, that...
13
by: magickarle | last post by:
Hi, I got a pass-through query (that takes about 15 mins to process) I would like to integrate variables to it. IE: something simple: Select EmplID from empl_Lst where empl_lst.timestamp between...
9
by: JRough | last post by:
I tried to pass the $result from a mysql_query in a url like this line Header("Location:clm_historyXL.php?_result=".$result); but on the redirect location clm_history.php page I get an error on...
3
by: swetha123 | last post by:
hello, I don't know how to use cookies please help me in this I am using the dream weaver cs4 I designed the navigation bar to my page using dream weaver cs4 navigation bar contains...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.