Error: Specified argument was out of the range of valid values.Parameter name Index.

Discussion in 'General Computer Support' started by siha, Dec 7, 2010.

  1. siha

    siha

    Joined:
    Nov 10, 2010
    Messages:
    1
    Hi, I'm trying to develop an application in c#. And so far was getting on fine until it started throwing the above error. Below is the code and the stack trace. Please assist.

    Code:
    using System;
    using System.Data;
    using System.Collections.Generic;
    using System.Linq;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Data.OleDb;
    using System.IO;


    namespace waferbreakage
    {
    public partial class dynamictabletest : System.Web.UI.Page
    {
    int numrows;
    int numcells;

    protected string tablename;
    protected string colnametxt;
    protected string dtypeddl;
    protected string fsizetxt;
    public string columnname;


    public struct controlID
    {
    public string colnameID;
    public string datatypeID;
    public string fieldsizeID;
    };
    controlID[] controlsID = new controlID[40];

    public struct data
    {
    public string columnname;
    public string datatype;
    public int fieldsize;
    }

    data[] inputdata = new data[1000];










    // Access Database oledb connection string
    // Using Provider Microsoft.Jet.OLEDB.4.0
    OleDbConnection myAccessConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + HttpContext.Current.Server.MapPath("MainDatabase1.mdb"));

    protected void openAccessConnection()
    {
    // If condition that can be used to check the access database connection
    // whether it is already open or not.
    if (myAccessConnection.State == ConnectionState.Closed)
    {
    myAccessConnection.Open();
    }
    }

    protected void closeAccessConnection()
    {
    // If condition to check the access database connection state
    // If it is open then close it.
    if (myAccessConnection.State == ConnectionState.Open)
    {
    myAccessConnection.Close();
    }

    }
    protected void Page_Load(object sender, EventArgs e)
    {

    }



    protected void btncreatetable_Click(object sender, EventArgs e)
    {
    tablename = txttablename.Text;
    OleDbCommand tablecommand = new OleDbCommand("CREATE TABLE " + tablename + "", myAccessConnection);
    OleDbCommand tablerefcommand = new OleDbCommand("insert into DatabaseRef(Tablename) values(@table_name)", myAccessConnection);

    OleDbParameter Tablename = new OleDbParameter("@table_name", OleDbType.VarChar);
    Tablename.Value = txttablename.Text;
    tablerefcommand.Parameters.Add(Tablename);

    try
    {
    openAccessConnection();
    tablecommand.ExecuteNonQuery();
    tablerefcommand.ExecuteNonQuery();
    closeAccessConnection();

    Response.Redirect("createdatabase.aspx");



    }
    catch (Exception exc)
    {
    Response.Write("Create Database Failure. Error Details : " + exc.Message.ToString());
    }



    }



    protected void DropDown1_SelectedIndexChanged(object sender, EventArgs e)
    {
    // Generate rows and cells

    numrows = int.Parse(DropDown1.SelectedItem.Value);
    numcells = int.Parse(DropDown2.SelectedItem.Value);
    int caseswitch;


    for (int j = 0; j <= numrows; j++)
    {
    TableRow r = new TableRow();

    for (int i = 0; i < numcells; i++)
    {

    TableCell c = new TableCell();
    caseswitch = i;

    switch (caseswitch)
    {
    case 0:
    if (j == 0)
    {
    c.Controls.Add(new LiteralControl("Column Name"));
    r.Cells.Add(c);
    }
    else
    {


    controlsID[j].colnameID = "colnametxtID" + j + i;
    TextBox coltxt = new TextBox();
    coltxt.ID = controlsID[j].colnameID;
    c.Controls.Add(coltxt);
    r.Cells.Add(c);





    }
    break;

    case 1:
    if (j == 0)
    {
    c.Controls.Add(new LiteralControl("Data Type"));
    r.Cells.Add(c);
    }
    else
    {
    dtypeddl = "datatypeddlID" + j + i;
    controlsID[j].datatypeID = dtypeddl;
    DropDownList ddl = new DropDownList();
    ddl.ID = dtypeddl;
    ddl.Items.Add("Text");
    ddl.Items.Add("Number");
    ddl.Items.Add("Memo");
    ddl.Items.Add("Date/Time");
    ddl.Items.Add("AutoNumber");
    c.Controls.Add(ddl);

    r.Cells.Add(c);


    }
    break;

    case 2:
    if (j == 0)
    {
    c.Controls.Add(new LiteralControl("Field Size"));
    r.Cells.Add(c);
    }
    else
    {
    fsizetxt = "fieldsizetxtID" + j + i;
    controlsID[j].fieldsizeID = fsizetxt;
    c.Controls.Add(new TextBox() { ID = controlsID[j].fieldsizeID, Width = 135 });
    r.Cells.Add(c);


    }
    break;
    }
    }

    Table1.Rows.Add(r);


    }
    }



    protected void Button1_Click(object sender, EventArgs e)
    {
    numrows = int.Parse(DropDown1.SelectedItem.Value);
    int caseswitch = numrows;

    switch (caseswitch)
    {
    case 1:
    for (int j = 1; j <= numrows; j++)
    {
    columnname = ((TextBox)Table1.Rows[j].FindControl(controlsID[j].colnameID)).Text;
    inputdata[j].columnname = columnname;
    Response.Write(inputdata[j].columnname);

    }
    break;


    }





    }


    }
    }


    Stack trace:
    Server Error in '/' Application.
    --------------------------------------------------------------------------------

    Specified argument was out of the range of valid values.
    Parameter name: index
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
    Parameter name: index

    Source Error:


    Line 225: for (int j = 1; j <= numrows; j++)
    Line 226: {
    Line 227: columnname = ((TextBox)Table1.Rows[j].FindControl(controlsID[j].colnameID)).Text;
    Line 228: inputdata[j].columnname = columnname;
    Line 229: Response.Write(inputdata[j].columnname);


    Source File: C:\Documents and Settings\eia1248\Desktop\waferbreakage\waferbreakage\createdatabase.aspx.cs Line: 227

    Stack Trace:


    [ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
    Parameter name: index]
    System.Web.UI.ControlCollection.get_Item(Int32 index) +8690450
    System.Web.UI.WebControls.TableRowCollection.get_Item(Int32 index) +30
    waferbreakage.dynamictabletest.Button1_Click(Object sender, EventArgs e) in C:\Documents and Settings\eia1248\Desktop\waferbreakage\waferbreakage\createdatabase.aspx.cs:227
    System.Web.UI.WebControls.Button.OnClick(EventArgs e) +118
    System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +112
    System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
    System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
    System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563




    --------------------------------------------------------------------------------
    Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1

    Thanks in advance! :)
     
    siha, Dec 7, 2010
    #1
    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. Robert Cooze

    index.htm or index.html ?

    Robert Cooze, Dec 7, 2005, in forum: NZ Computing
    Replies:
    15
    Views:
    628
    Robert Cooze
    Dec 13, 2005
  2. Luke O'Malley

    Program Index: cannot view entire index XP

    Luke O'Malley, May 3, 2008, in forum: Computer Support
    Replies:
    2
    Views:
    517
    Luke O'Malley
    May 5, 2008
  3. Marc Wossner

    Raw values and exposure values

    Marc Wossner, Jun 19, 2008, in forum: Digital Photography
    Replies:
    0
    Views:
    351
    Marc Wossner
    Jun 19, 2008
  4. Matt Schneyer

    value of performance index and reliability index

    Matt Schneyer, Nov 14, 2008, in forum: Windows 64bit
    Replies:
    10
    Views:
    927
    Matt Schneyer
    Nov 20, 2008
  5. Anjut
    Replies:
    0
    Views:
    2,100
    Anjut
    Nov 14, 2009
Loading...

Share This Page