Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   911...Need Help! : Length cannot be less than zero. Parameter name : length (http://www.velocityreviews.com/forums/t117065-911-need-help-length-cannot-be-less-than-zero-parameter-name-length.html)

manmit.walia@gmail.com 01-10-2006 01:25 PM

911...Need Help! : Length cannot be less than zero. Parameter name : length
 
Hello All and Thank You for your time,
I am stuck on this exception handleing error. The problem is that when
I run my application the application works perfect but sometimes, I get
this error. I do not know where it is causing it but my guess would be
something with the function below. Any help would be greatfull, as this
would be a learning experience for me.

For this example: swTitle.Text = "AutoCAD 2004"
After the user selects the product from a listbox, a datagrid is binded
to an arraylist which is field with all of the <EmployeeName>
associated with that product.
So I have split the EmployeeName up into four fields (FirstName, MI,
LastName, Email). and each field will be a column in the datagrid.


Function Task:
**********************
1) Read XML file
2) Use XPath to find a particular node
3) Query the node for fields and print out the fields in datagrid


XML File Example:
**********************
<EMPProductType>
<ProductType>AutoCAD 2004</ProductType>
<ManagerEMail>deon.payne@email.com</ManagerEMail>
<EmployeeName>Joe,,Alexander,joe.alexander@email.c om</EmployeeName>
<EmployeeName>Joe,,Allen,joe.allen@email.com</EmployeeName>
<EmployeeName>Harold,,Anderson,harold.anderson@ema il.com</EmployeeName>

<EmployeeName>Kent,,Berner,kent.berner@email.com </EmployeeName>
<EmployeeName>Tommy,,Childers,tommy.childers@email .com</EmployeeName>
</EMPProductType>

Function:
**********************
void GetUserList()
{

XmlDocument doc = new XmlDocument();
doc.Load("http://dpi948.delta.com/dtedmprod:/Field_Operations/ETAM/SFT/Software.xml");

//XmlNode sw;
XmlNodeList sw;
XmlNode root = doc.DocumentElement;

// SEARCH XML FILE
string t = "'" + swTitle.Text + "'";
sw=root.SelectNodes("//EMPProductType[ProductType=" + t + "
]/EmployeeName");
total = sw.Count;
// RETURN DATA FROM XPATH
if(sw != null)
{

for (int i=0; i < sw.Count; i++)
{
len = sw[i].InnerXml.Length;
ind = sw[i].InnerXml.IndexOf(',');
fn = sw[i].InnerXml.Substring(0, ind);
ind = ind + 1;
len = len - ind;
s1 = sw[i].InnerXml.Substring(ind,len);
ind = s1.IndexOf(',');
mi = s1.Substring(0, ind);
if(mi == "")
{
mi = "x";
}
ind = ind + 1;
len = len - ind;
s1 = s1.Substring(ind, len);
ind = s1.IndexOf(',');
ln = s1.Substring(0, ind);
ind = ind + 1;
len = len - ind;
ue = s1.Substring(ind, len);

ul.Add (new user(fn, mi, ln, ue));


temp = temp + " " + fn + " " + mi + " " + ln + " " + ue + "<br>";

}
usedCount.Text = total.ToString();
myDataGrid.DataSource=ul;
myDataGrid.DataBind();
}

}


=?Utf-8?B?Q293Ym95IChHcmVnb3J5IEEuIEJlYW1lcikgLSBNVlA=?= 01-10-2006 03:25 PM

RE: 911...Need Help! : Length cannot be less than zero. Parameter na
 
Just a guess, but it is most likely the fact that most of your people have no
middle name. From the error, you are probably erroring out trying to submit
to a database. If so, you will have to set the default for that parameter to
null and not set it when the string is empty.

if(txtMiddleName.Text.ToString().Length >= 1)
{
//Set Parameter
}
else
{
//Do nothing
}

You do not need the else, but it illustrates the point.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************


"manmit.walia@gmail.com" wrote:

> Hello All and Thank You for your time,
> I am stuck on this exception handleing error. The problem is that when
> I run my application the application works perfect but sometimes, I get
> this error. I do not know where it is causing it but my guess would be
> something with the function below. Any help would be greatfull, as this
> would be a learning experience for me.
>
> For this example: swTitle.Text = "AutoCAD 2004"
> After the user selects the product from a listbox, a datagrid is binded
> to an arraylist which is field with all of the <EmployeeName>
> associated with that product.
> So I have split the EmployeeName up into four fields (FirstName, MI,
> LastName, Email). and each field will be a column in the datagrid.
>
>
> Function Task:
> **********************
> 1) Read XML file
> 2) Use XPath to find a particular node
> 3) Query the node for fields and print out the fields in datagrid
>
>
> XML File Example:
> **********************
> <EMPProductType>
> <ProductType>AutoCAD 2004</ProductType>
> <ManagerEMail>deon.payne@email.com</ManagerEMail>
> <EmployeeName>Joe,,Alexander,joe.alexander@email.c om</EmployeeName>
> <EmployeeName>Joe,,Allen,joe.allen@email.com</EmployeeName>
> <EmployeeName>Harold,,Anderson,harold.anderson@ema il.com</EmployeeName>
>
> <EmployeeName>Kent,,Berner,kent.berner@email.com </EmployeeName>
> <EmployeeName>Tommy,,Childers,tommy.childers@email .com</EmployeeName>
> </EMPProductType>
>
> Function:
> **********************
> void GetUserList()
> {
>
> XmlDocument doc = new XmlDocument();
> doc.Load("http://dpi948.delta.com/dtedmprod:/Field_Operations/ETAM/SFT/Software.xml");
>
> //XmlNode sw;
> XmlNodeList sw;
> XmlNode root = doc.DocumentElement;
>
> // SEARCH XML FILE
> string t = "'" + swTitle.Text + "'";
> sw=root.SelectNodes("//EMPProductType[ProductType=" + t + "
> ]/EmployeeName");
> total = sw.Count;
> // RETURN DATA FROM XPATH
> if(sw != null)
> {
>
> for (int i=0; i < sw.Count; i++)
> {
> len = sw[i].InnerXml.Length;
> ind = sw[i].InnerXml.IndexOf(',');
> fn = sw[i].InnerXml.Substring(0, ind);
> ind = ind + 1;
> len = len - ind;
> s1 = sw[i].InnerXml.Substring(ind,len);
> ind = s1.IndexOf(',');
> mi = s1.Substring(0, ind);
> if(mi == "")
> {
> mi = "x";
> }
> ind = ind + 1;
> len = len - ind;
> s1 = s1.Substring(ind, len);
> ind = s1.IndexOf(',');
> ln = s1.Substring(0, ind);
> ind = ind + 1;
> len = len - ind;
> ue = s1.Substring(ind, len);
>
> ul.Add (new user(fn, mi, ln, ue));
>
>
> temp = temp + " " + fn + " " + mi + " " + ln + " " + ue + "<br>";
>
> }
> usedCount.Text = total.ToString();
> myDataGrid.DataSource=ul;
> myDataGrid.DataBind();
> }
>
> }
>
>


manmit.walia@gmail.com 01-10-2006 03:29 PM

Re: 911...Need Help! : Length cannot be less than zero. Parameter na
 
Thanks Cowboy,
But am I not doing that here:

mi = s1.Substring(0, ind);
if(mi == "")
{
mi = "x";

}



All times are GMT. The time now is 10:59 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.