473,406 Members | 2,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

need join help

cj
My code below gives me "SQL: Column 'BTN' is not found."

It will work if I use an inner join or just join but those two joins
don't return all the rows. BTN has 5 rows, but arcust01 has only has
matching records for 2 of them. I need the other 3 returned with nulls
in the fields from arcust01.

How can I do this?

Imports System.Data.OleDb

Public Class Form1
Dim myOleDbConnection As OleDbConnection
Dim myOleDbCommand As OleDbCommand
Dim myOleDbDataAdapter As OleDbDataAdapter

Dim dt As New DataTable

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
myOleDbConnection = New
OleDbConnection("Provider=vfpoledb.1;Data Source=c:\;Collating
Sequence=general")
myOleDbCommand = New OleDbCommand
myOleDbDataAdapter = New OleDbDataAdapter

Dim fields As String = "select btn.btn, arcust01.lastpay,
arcust01.balance "
Dim from As String = "from btn outer join f:\chris\arcust01
arcust01 on btn.btn = arcust01.custno"

myOleDbCommand.CommandText = fields & from
'myOleDbCommand.CommandText = "select btn.btn from btn"
myOleDbCommand.Connection = myOleDbConnection

myOleDbDataAdapter.SelectCommand = myOleDbCommand

myOleDbDataAdapter.Fill(dt)

DataGridView1.DataSource = dt
MessageBox.Show("done!")
End Sub

End Class
Dec 13 '07 #1
2 1160
Hi Chris,

Based on my understanding, you have two database tables named 'BTN' and
'Arcust01'. The table 'BTN' has 5 rows in it and there're 2 rows in the
table 'Arcust01' matching 2 of the 5 rows in the table 'BTN'. What you want
is to query both two tables and return all the 5 rows in the table 'BTN'
among which the 3 rows not being matched returned with nulls in the fields
from the table 'Arcust01'. If I'm off base, please feel free to let me know.

You should use left outer join to get what you want. The following is a
sample:

Dim sQry As String = "select btn.btn, arcust01.lastpay, arcust01.balance
from btn left outer join f:\chris\arcust01 arcust01 on btn.btn =
arcust01.custno"

myOleDbCommand.CommandText = sQry

Hope this helps.
If you have any question, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Dec 14 '07 #2
cj
Thank you very much. That is exactly what I wanted.
Linda Liu[MSFT] wrote:
Hi Chris,

Based on my understanding, you have two database tables named 'BTN' and
'Arcust01'. The table 'BTN' has 5 rows in it and there're 2 rows in the
table 'Arcust01' matching 2 of the 5 rows in the table 'BTN'. What you want
is to query both two tables and return all the 5 rows in the table 'BTN'
among which the 3 rows not being matched returned with nulls in the fields
from the table 'Arcust01'. If I'm off base, please feel free to let me know.

You should use left outer join to get what you want. The following is a
sample:

Dim sQry As String = "select btn.btn, arcust01.lastpay, arcust01.balance
from btn left outer join f:\chris\arcust01 arcust01 on btn.btn =
arcust01.custno"

myOleDbCommand.CommandText = sQry

Hope this helps.
If you have any question, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
Dec 18 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: B. Fongo | last post by:
I learned MySQL last year without putting it into action; that is why I face trouble in formulating my queries. Were it a test, then you would have passed it, because your queries did help me...
9
by: netpurpose | last post by:
I need to extract data from this table to find the lowest prices of each product as of today. The product will be listed/grouped by the name only, discarding the product code - I use...
3
by: Prem | last post by:
Hi, I am having many problems with inner join. my first problem is : 1) I want to know the precedance while evaluating query with multiple joins. eg. select Employees.FirstName,...
3
by: ColdCanuck | last post by:
Help! I'm trying to understand the new ANSI join syntax (after many years of coding using the old style). I am now working with an application that only understands ANSI syntax so I am...
3
by: google | last post by:
I have a database with four table. In one of the tables, I use about five lookup fields to get populate their dropdown list. I have read that lookup fields are really bad and may cause problems...
3
by: Danielle | last post by:
Hello group- I am having a problem where joined tables are returning too many rows. Here is my scenario - I am trying to create a temporary table from parts of three tables - the important...
2
by: Terry Olsen | last post by:
I need to get information from 3 tables in an MDB file. I need all the columns in the first table. I need 2 columns in the 2nd table where it's primary key matches a column in the first table....
1
by: write2ashokkumar | last post by:
hi... i have the table like this, Table Name : sample Total Records : 500000 (Consider like this) Sample Records: id ------------ name
1
by: write2ashokkumar | last post by:
hi... i have the table like this, Table Name : sample Total Records : 500000 (Consider like this) Sample Records: ----------------
2
by: speavey | last post by:
When I run this query, I get an ORDER BY error "Incorrect syntax near the keyword 'ORDER'. I've bolded it below. If I take the ORDER by out then it works correctly, but I need the ORDER BY...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.