| | |
SQLDataReader to read query issue
Please support our VB.NET advertiser: Intel Parallel Studio Home
Thread Solved |
Hi all; I'd be really grateful if someone could assist me with this problem.
What i am trying to do is create a query that pulls information from two different tables: tblBooking and tblConcessions.
tblBooking holds the ID number of tblConcessions as a ForeignKey.
What i need within my statement is to pull some information from tblBooking and then replace the concessionID number with the concessionName from the concession table.
My program then reads this data and places it into a ListView box.
I've been able to get it to read just from one table; but i'm having trouble with pulling data from the other table.
My code so far is as follows.
I have tried using a subquery; i have not used subqueries before so i'm sure i'm doing something wrong or missing some critical point.
This is what i tried:
I got the error:
"Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression."
Is a subquery the best way to go about achieving this or is there a better way?
Thanks for your time.
What i am trying to do is create a query that pulls information from two different tables: tblBooking and tblConcessions.
tblBooking holds the ID number of tblConcessions as a ForeignKey.
What i need within my statement is to pull some information from tblBooking and then replace the concessionID number with the concessionName from the concession table.
My program then reads this data and places it into a ListView box.
I've been able to get it to read just from one table; but i'm having trouble with pulling data from the other table.
My code so far is as follows.
VB.NET Syntax (Toggle Plain Text)
Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click lvBookings.Items.Clear() Dim itm As ListViewItem Dim varCommand As String varCommand = "SELECT BookingID, C_ID, StartDate, EndDate FROM tblBooking WHERE " If Not txtBSBookingID.Text = Nothing Then varCommand = varCommand & "BookingID LIKE '" & txtBSBookingID.Text & "'" ElseIf cboInitials.SelectedIndex > -1 Or Not cboInitials.SelectedItem = "None" Then varCommand = varCommand & "FFInitiatedBy LIKE '" & cboInitials.SelectedItem & "'" End If objCommand = New SqlCommand(varCommand, objConnection) Try objConnection.Open() Dim reader As SqlDataReader = objCommand.ExecuteReader While reader.Read() str(0) = reader("BookingID") str(1) = reader("C_ID") str(2) = reader("StartDate") str(3) = reader("EndDate") itm = New ListViewItem(str) lvBookings.Items.Add(itm) End While Finally objConnection.Close() End Try
I have tried using a subquery; i have not used subqueries before so i'm sure i'm doing something wrong or missing some critical point.
This is what i tried:
VB.NET Syntax (Toggle Plain Text)
"SELECT BookingID, (SELECT ConcessionName " & _ "FROM tblConcessions " & _ "INNER JOIN tblBooking " & _ "ON tblConcessions.ConcessionID=tblBooking.C_ID), "& _ "StartDate, EndDate FROM tblBooking WHERE "
I got the error:
"Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression."
Is a subquery the best way to go about achieving this or is there a better way?
Thanks for your time.
The world has been turned upside down to me...sounds like chaos...and i do love chaos!
Awsome! Solved it! I've been stuck trying to figure this out for days.
I used 'INNER JOIN' to solve the problem:
I just looked at the join statement in more detail and didn't use a subquery. I tried creating additional queries and then calling them and for some reason i couldn't get it to work in the i needed it to. Thanks for your time babbu!
I used 'INNER JOIN' to solve the problem:
VB.NET Syntax (Toggle Plain Text)
varCommand = "SELECT tblBooking.BookingID, tblConcessions.ConcessionName, " & _ "tblGardenCentre.GardenCentreName, tblBooking.StartDate," & _ "tblBooking.EndDate " & _ "FROM tblBooking " & _ "INNER JOIN tblConcessions " & _ "ON tblBooking.C_ID = tblConcessions.ConcessionID " & _ "INNER JOIN tblGardenCentre " & _ "ON tblBooking.GC_ID = tblGardenCentre.GardenCentreID " & _ "WHERE "
The world has been turned upside down to me...sounds like chaos...and i do love chaos!
![]() |
Similar Threads
- in the below code syntax error is being showed in the" insert into " kindly solve it. (C#)
- complex query issue (ColdFusion)
- Read File Issue (C++)
- Error Parsing Query in Token Line ... (VB.NET)
- HOWTO: Run a Query on a Database using ODBC and return all Results into a DGV Object (C#)
- Need help resolving background issue.. (Viruses, Spyware and other Nasties)
Other Threads in the VB.NET Forum
- Previous Thread: Storing Data in Excel Worksheet Invisible to the User
- Next Thread: Assigning a Variable to a Class
| Thread Tools | Search this Thread |
"crystal .net .net2005 30minutes 2008 access add application arithmetic array assignment basic binary box button buttons center click code combo combobox component connectionstring convert cpu data database databasesearch datagrid datagridview design dissertation dissertations dissertationthesis dosconsolevb.net editvb.net employees excel exists firewall folder image images isnumericfuntioncall listview login math memory mobile module ms msaccess mssqlbackend mysql navigate net opacity pan peertopeervideostreaming picturebox picturebox1 port print printpreview problemwithinstallation project record regex reports" reuse right-to-left save savedialog search serial sorting sqldatbase storedprocedure string temp textbox timer updown upload useraccounts usercontrol vb vb.net vb.netcode vb.nettoolboxvisualbasic2008sidebar vbnet view vista visual visualbasic visualbasic.net visualstudio web wpf xml





