Web App, DataSet, IndexOutOfRange

I

Iwan Petrow

Hi,

I have two tables with relation:

Table1:
T1_id
T2_id (foreign key,allow null)
.....

Table2
T2_id
.....

I show two tables in Web form with controls binded to a dataset (I use
a Web service to get this dataset). But when T2_id (in Table1) is null,
there is not a "row" for Table2 in the dataset. When controls binds to
corresponding values - I have exception IndexOutOfRange. When I have
this situation I want the controls to show empty strings.

How could I do this?

Thanks.
 
A

Alvin Bruney [Microsoft MVP]

The control cannot show empty strings because it is being bound to an empty
dataset. Instead you should test for an empty dataset and take some action -
a user prompt for instance. Consider:

if(DataSet1 != null && DataSet1.Table != null && DataSet1.Tables.Count > 0
&& DataSet1.Tables.Rows.Count > 0)

then bind else display a no-data-prompt.

--
Regards
Alvin Bruney
[Shameless Author Plug]
The Microsoft Office Web Components Black Book with .NET
available at www.lulu.com/owc
 
I

Iwan Petrow

Hi,

But all my controls (which shows values) are in one ASP page. So I
aways have to bind? Is there a way to bind only part of my controls (I
prefer this) or I have to create another web page?

Thanks.
 

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

Top