911...Need Help! : Length cannot be less than zero. Parameter name : length

Discussion in 'ASP .Net' started by manmit.walia@gmail.com, Jan 10, 2006.

  1. Guest

    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></ManagerEMail>
    <EmployeeName>Joe,,Alexander,</EmployeeName>
    <EmployeeName>Joe,,Allen,</EmployeeName>
    <EmployeeName>Harold,,Anderson,</EmployeeName>

    <EmployeeName>Kent,,Berner,</EmployeeName>
    <EmployeeName>Tommy,,Childers,</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.InnerXml.Length;
    ind = sw.InnerXml.IndexOf(',');
    fn = sw.InnerXml.Substring(0, ind);
    ind = ind + 1;
    len = len - ind;
    s1 = sw.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();
    }

    }
     
    , Jan 10, 2006
    #1
    1. Advertising

  2. 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!
    ***************************


    "" 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></ManagerEMail>
    > <EmployeeName>Joe,,Alexander,</EmployeeName>
    > <EmployeeName>Joe,,Allen,</EmployeeName>
    > <EmployeeName>Harold,,Anderson,</EmployeeName>
    >
    > <EmployeeName>Kent,,Berner,</EmployeeName>
    > <EmployeeName>Tommy,,Childers,</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.InnerXml.Length;
    > ind = sw.InnerXml.IndexOf(',');
    > fn = sw.InnerXml.Substring(0, ind);
    > ind = ind + 1;
    > len = len - ind;
    > s1 = sw.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?Q293Ym95IChHcmVnb3J5IEEuIEJlYW1lcikgLSBN, Jan 10, 2006
    #2
    1. Advertising

  3. Guest

    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";

    }
     
    , Jan 10, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Mason

    Length cannot be less than zero

    John Mason, Apr 16, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    6,735
    John Mason
    Jun 2, 2004
  2. =?Utf-8?B?SG96aQ==?=
    Replies:
    1
    Views:
    7,005
    Ken Cox [Microsoft MVP]
    Jun 2, 2004
  3. MattB

    Custom CheckBoxList "Length cannot be less than zero" error

    MattB, Aug 2, 2004, in forum: ASP .Net Building Controls
    Replies:
    4
    Views:
    263
    Bill Cohagan
    Sep 28, 2004
  4. ctk70
    Replies:
    2
    Views:
    510
    ctk70
    Feb 10, 2005
  5. Replies:
    0
    Views:
    490
Loading...

Share This Page