Solved

Help with Query not bringing back record using SQLDataReader and DataTable

Posted on 2013-05-21
3
258 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
Comment Utility
Hi,

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

Giannis
0
 
LVL 2

Author Comment

by:bignadad
Comment Utility
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
Comment Utility
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how the fundamental information of how to create a table.

744 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

8 Experts available now in Live!

Get 1:1 Help Now