0

私は 2 つのテーブル、製品、および著者を持っています。著者テーブルには ID によって製品テーブルに関連する列があるため、ID に基づいて適切な行を取得するために以下の選択ステートメントを実行しました。ただし、作成者テーブルにはデータが含まれていない可能性があるため、製品テーブルの ID はありません。この場合、製品からの情報は表示されません。

だから私の質問は、これをどのように処理するのですか?

    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

ありがとうございました!

4

1 に答える 1

0
Select * from table1 as A left outer join table2 as B on (A.id=B.id) where a.id=101 and b.pid=102
于 2013-08-24T10:04:01.770 に答える