?
Solved

Help with Query not bringing back record using SQLDataReader and DataTable

Posted on 2013-05-21
3
Medium Priority
?
275 Views
Last Modified: 2013-05-21
Dim strSql = " SELECT OEMPartNumber,OEMDescription,OEMSubnumber FROM JD Inner Join amipartnumbers on " & _
            " amipartnumbers.OEMItem=JD.OEMPartNumber WHERE " & _
            " JD.OEMPartNumber= '" & enterNumber & "' or " & _
            " JD.OEMSubnumber= '" & enterNumber & "'" & _
            " UNION SELECT OEMPartNumber,OEMDescription,OEMSubnumber FROM IH Inner Join amipartnumbers on " & _
            " amipartnumbers.OEMItem=IH.OEMPartNumber WHERE " & _
            " IH.OEMPartNumber= '" & enterNumber & "' or " & _
            " IH.OEMSubnumber= '" & enterNumber & "'"

Open in new window


That is my query

Here is my table layout

imports
----------------
OEMPartNumber  | AMIPartNumber
AR77530        |
AR12345        |

JDSubs
---------------------------
OEMPartNumer    | OEMSubNumber
AR65123         | AR77530
AR12345         | AR56242

AMI
---------------------------
Item            | OEMItem   | Description
AMAR65123       | AR65123   | Axle
AMAR56242       | AR12345   | Spindle

Open in new window


This is my DataTableFill code
For i As Integer = 0 To datatableFill.Rows.Count - 1
                Me.txtAMINumber.Text = datatableFill.Rows(i)("Item")
                Me.txtDescription.Text = datatableFill.Rows(i)("Description")
                Me.txtOEMPartNumber.Text = datatableFill.Rows(i)("OEMPartNumber")
                Me.txtOEMsubnumber.Text = FixNull(datatableFill.Rows(i)("OEMsubnumber"))
                Me.txtOEMDescription.Text = datatableFill.Rows(i)("OEMDescription")
            Next

Open in new window


Im getting this error
Column 'Item' does not belong to table .
0
Comment
Question by:bignadad
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 23

Accepted Solution

by:
Ioannis Paraskevopoulos earned 2000 total points
ID: 39185980
Hi,

You are only selecting OEMPartnumber, OEMDescription and OEMSubnumber. Add Item and Description in your query.

Giannis
0
 
LVL 2

Author Comment

by:bignadad
ID: 39185991
i changed to this but still not working. Item and Description are not on JD table
sorry some of my table names have changed. JDSubs is now JD

Dim strSql = " SELECT OEMPartNumber,OEMDescription,OEMSubnumber,Item,Description FROM JD Inner Join amipartnumbers on " & _
            " amipartnumbers.OEMItem=JD.OEMPartNumber WHERE " & _
            " JD.OEMPartNumber= '" & enterNumber & "' or " & _
            " JD.OEMSubnumber= '" & enterNumber & "'" & _
            " UNION SELECT OEMPartNumber,OEMDescription,OEMSubnumber FROM IH Inner Join amipartnumbers on " & _
            " amipartnumbers.OEMItem=IH.OEMPartNumber WHERE " & _
            " IH.OEMPartNumber= '" & enterNumber & "' or " & _
            " IH.OEMSubnumber= '" & enterNumber & "'"

Open in new window

0
 
LVL 2

Author Comment

by:bignadad
ID: 39185997
Sorry that did work. didn't apply it to both Select's. Thanks!

I was thinking that SELECT column, column column FROM JD would only select columns from JD.
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question