471,570 Members | 934 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,570 software developers and data experts.

SystemOutOfRange Exception

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[i]["ADCN"] is DBNull)
{ds.Tables[0].Rows[i]["NewADCN"] =
Convert.ToInt32(ds.Tables[0].Rows[i]["ADCN"]);}
else
{ds.Tables[0].Rows[i]["NewADCN"] = "&nbsp;"; }
}

*** Sent via Developersdex http://www.developersdex.com ***
Dec 1 '05 #1
2 1812
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

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Will Chamberlain" wrote:
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[i]["ADCN"] is DBNull)
{ds.Tables[0].Rows[i]["NewADCN"] =
Convert.ToInt32(ds.Tables[0].Rows[i]["ADCN"]);}
else
{ds.Tables[0].Rows[i]["NewADCN"] = " "; }
}

*** Sent via Developersdex http://www.developersdex.com ***

Dec 1 '05 #2
Hi,

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

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Will Chamberlain" <wi**************@devdex.com> wrote in message
news:OW*************@TK2MSFTNGP15.phx.gbl...
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
"&nbsp;" 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[i]["ADCN"] is DBNull)
{ds.Tables[0].Rows[i]["NewADCN"] =
Convert.ToInt32(ds.Tables[0].Rows[i]["ADCN"]);}
else
{ds.Tables[0].Rows[i]["NewADCN"] = "&nbsp;"; }
}

*** Sent via Developersdex http://www.developersdex.com ***

Dec 1 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Nicolas Fleury | last post: by
1 post views Thread by Old Wolf | last post: by
11 posts views Thread by Master of C++ | last post: by
4 posts views Thread by maricel | last post: by
2 posts views Thread by Alex | last post: by
44 posts views Thread by craig | last post: by
40 posts views Thread by Kevin Yu | last post: by
3 posts views Thread by JohnDeHope3 | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by lumer26 | last post: by
reply views Thread by lumer26 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.