Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > General Computer Discussion > General Computer Support > Error: Specified argument was out of the range of valid values.Parameter name Index.

Reply
Thread Tools

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

 
 
siha siha is offline
Junior Member
Join Date: Nov 2010
Posts: 1
 
      12-07-2010
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\waferbreaka ge\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_I tem(Int32 index) +30
waferbreakage.dynamictabletest.Button1_Click(Objec t sender, EventArgs e) in C:\Documents and Settings\eia1248\Desktop\waferbreakage\waferbreaka ge\createdatabase.aspx.cs:227
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +118
System.Web.UI.WebControls.Button.RaisePostBackEven t(String eventArgument) +112
System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection 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!
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Specified argument was out of range of valid values rajarameshvarma@gmail.com ASP .Net 0 10-27-2006 04:57 AM
Specified argument was out of the range of valid values. Parameter name: value? darrel ASP .Net 0 08-14-2006 10:32 PM
error: Specified argument was out of the range of valid values. Parameter name: index Dave ASP .Net Datagrid Control 11 07-09-2006 01:19 PM
Specified argument was out of the range of valid values. Par subdhar ASP .Net 9 11-09-2004 02:39 PM
Specified argument was out of the range of valid values. Parameter name: 0 Todd Perkins ASP .Net 0 09-15-2004 07:46 PM



Advertisments