Solved

Help with Query not bringing back record using SQLDataReader and DataTable

Posted on 2013-05-21
3
261 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
  • 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

932 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now