SystemOutOfRange Exception

  • Thread starter Thread starter Will Chamberlain
  • Start date Start date
W

Will Chamberlain

The code below is giving me an error saying that row 0 does not exist. I
have written the code in VB.NET and it works flawlessly. I am in the
process of converting to C# code. This is supposed to work by assigning
" " where the ADCN field is returned NULL. This SQL server tables
allows for NULLs (completion date, etc...). What am I missing here?

int dsRowCount = ds.Tables[0].Rows.Count;

for (int i=0; i <= dsRowCount; i++)
{
if (ds.Tables[0].Rows["ADCN"] is DBNull)
{ds.Tables[0].Rows["NewADCN"] =
Convert.ToInt32(ds.Tables[0].Rows["ADCN"]);}
else
{ds.Tables[0].Rows["NewADCN"] = "&nbsp;"; }
}
 
A classic "VB.NET-er" error.

for (int i=0; i <= dsRowCount; i++)

needs to be

for (int i=0; i <dsRowCount; i++)

Cheers,
Peter
 
Hi,

Why dont you use foreach, IMO it's clearer this way

cheers,
 

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

Back
Top