Вопрос

I have 2 tables, products, and author, the author table has a column that relates to the product table by an ID so I have done a select statement below to get the right rows based on the ID's. However the author table might not have any data in and therefore no ID to the product table. If this is the case then the information from the product doesn't show up.

So my question is how do i handle this?

    Dim ID As String = Request("id")
    If String.IsNullOrEmpty(ID) Then
        Response.Redirect("/Default.aspx")
    End If

    Try
        Using conn As New OleDbConnection(strcon)
            conn.Open()
            Dim cmd As String = "SELECT * FROM tblProducts, tblPrdAuthor " & _
                                "WHERE tblProducts.ID = " & ID & " AND tblPrdAuthor.paPrdID = tblProducts.ID"
            Using da As New OleDbDataAdapter(cmd, conn)
                Dim ds As New DataSet()
                da.Fill(ds)

                'Bind to the repeater
                rptProduct.DataSource = ds
                rptProduct.DataBind()
            End Using
        End Using
    Catch ex As Exception
        Throw ex
    End Try

Thank you!

Это было полезно?

Решение

Select * from table1 as A left outer join table2 as B on (A.id=B.id) where a.id=101 and b.pid=102
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top