Saturday, 24 August 2013

OLEDBCommand handle missing database row

OLEDBCommand handle missing database row

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!

No comments:

Post a Comment