Solved

Help with Query not bringing back record using SQLDataReader and DataTable

Posted on 2013-05-21
3
272 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 500 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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.

738 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