Table not found error

  • Thread starter Thread starter Jim Mesara
  • Start date Start date
J

Jim Mesara

I have the following bit of code. What it does it query the database for
address information, and there can be multiple addresses for each person.
For
each person, the repeater creates a row. Each repeater row can display as
many addresses as are needed (usually one, but it can be more.)

For Each strTemp In strArray
objAdp = New OleDbDataAdapter(strSQL, objConn)
objAdp.Fill(objDS, strTemp)
Next

Response.Write("<br>Table count = " & objDS.Tables.Count)

If objDS.Tables.Count > 1 Then
'Bind as normal
Repeater1.DataSource = objDS.Tables()
Else
'Only bind the single table
Repeater1.DataSource = objDS.Tables(0)
End If
Repeater1.DataBind()


If I enter two people, each with one address, the repeater displays
correctly and the code works fine. If I enter one person with multiple
addresses, I get the following error:

Error: Cannot find table 1

So it looks like the code above thinks that there is another table in the
objDS, but the Response.Write for the query causing the problem says the
table count is 1. So I'm not sure why the Repeater control is trying to bind
more than one table. All the addresses associated with the person display
properly. The error occurs after the addresses have been displayed properly.
Any ideas why the code would think there is an extra table?

Thank you for you help,
Jim
 
Jim:

Can you post the whole code snippet? What is the count under the scenario
where the exception is caused. Can you wrap the first block in a try catch
block and show the whole ex.ToSTring?

Thanks,

Bill
 
I found the problem. Instead of this:

If objDS.Tables.Count > 1 Then
'Bind as normal
Repeater1.DataSource = objDS.Tables()
Else
'Only bind the single table
Repeater1.DataSource = objDS.Tables(0)
End If
Repeater1.DataBind()

I just did this:

Repeater1.DataSource = objDS.Tables()
Repeater1.DataBind()

On an earlier version of the code I had to use the first version of the
code, but apparently, this is no longer necessary.
 
Back
Top