Multiple tables not displayed when binding to a Repeater

J

Jim French

I have a page that takes a comma delimited string and needs to bind to a
Repeater control. The string is split into an Array, and each value is put
into a DataBase query via a For Each loop. The purpose is to retrieve
address information for the user. Sometimes, the address_fk field in the
people table is null, so there will be no linking address information. In
this case, the section to be displayed asks if the user would like to create
an address. (The section information is not shown.)

If the first array variable contains an id with an associated address, no
problem - the page acts correctly. The problem I have is that if the first
variable passed does not retrieve any rows from the address table, then the
second query (which does have values in the address table) is not displayed.
The If clause in the Page_Load event below is to retrieve the People ID
field, which must be shown in the Repeater section whether there is an
associated address or not.

I have verified that all works as I think it should up until the DataBind
method. Right before I bind to the Repeater, the row count is correct (0,2
respectively), and the table count is correct (2). But when I bind, only the
first row (no address data) is displayed. The Repeater only fires once, and
never fires for the second DataSet table, the one with values. What is
happening here?

(In the If clause, I clear the columns in the table because certain controls
in the Repeater are hidden based on the number of rows returned. If one row
is returned, it checks to see if there is one column (no address
information) or nine columns (there is address info.) If you need to see
further information, please let me know.)

Thank you very much,
Jim

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
Session("myVars") = "46,44"

'Split the array
strArray = Session("myVars").ToString.Split(",")

'Declare database variables
objConn = New OleDbConnection(Application("dbString"))
objComm = New OleDbCommand(strSQL, objConn)
objDS = New DataSet()
objConn.Open()

'Loop through the addresses of each party
For Each strTemp In strArray
strSQL = "select
ad.id,name,Address1,Address2,City,State_ID_Fk,Zip_Code,pa.id as
PeopleID,pa.id_number " _
& "from Address ad, People_Address pa where pa.id_number =
ad.ID_Number " _
& "and pa.id = " & strTemp

objAdp = New OleDbDataAdapter(strSQL, objConn)
objAdp.Fill(objDS, strTemp)

'If there are no rows, then repopulate with a new query
because the Repeater
'needs to have rows to work with
If objDS.Tables(strTemp).Rows.Count = 0 Then
strSQL = "select id_number from caseflow.people_address
where " _
& "address_fk is null and id = " & strTemp
objAdp.SelectCommand.CommandText = strSQL
objDS.Tables(strTemp).Columns.Clear()
objAdp.Fill(objDS.Tables(strTemp))
End If
Next

Response.Write("<br>My count = " & objDS.Tables.Count)
Repeater1.DataSource = objDS
Repeater1.DataBind()
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top