[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Help with Query not bringing back record using SQLDataReader and DataTable

Posted on 2013-05-21
3
Medium Priority
?
276 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 feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

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…
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
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…

649 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