need join help

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • cj

    #1

    need join help

    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.Ole Db

    Public Class Form1
    Dim myOleDbConnecti on As OleDbConnection
    Dim myOleDbCommand As OleDbCommand
    Dim myOleDbDataAdap ter As OleDbDataAdapte r

    Dim dt As New DataTable

    Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
    System.EventArg s) Handles Button1.Click
    myOleDbConnecti on = New
    OleDbConnection ("Provider=vfpo ledb.1;Data Source=c:\;Coll ating
    Sequence=genera l")
    myOleDbCommand = New OleDbCommand
    myOleDbDataAdap ter = New OleDbDataAdapte r

    Dim fields As String = "select btn.btn, arcust01.lastpa y,
    arcust01.balanc e "
    Dim from As String = "from btn outer join f:\chris\arcust 01
    arcust01 on btn.btn = arcust01.custno "

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

    myOleDbDataAdap ter.SelectComma nd = myOleDbCommand

    myOleDbDataAdap ter.Fill(dt)

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

    End Class
  • Linda Liu[MSFT]

    #2
    RE: need join help

    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.lastpa y, arcust01.balanc e
    from btn left outer join f:\chris\arcust 01 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.

    Comment

    • cj

      #3
      Re: need join help

      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.lastpa y, arcust01.balanc e
      from btn left outer join f:\chris\arcust 01 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.
      >

      Comment

      Working...