Saturday, March 31, 2012

System.IndexOutOfRangeException: Index was outside the bounds of the array

Hi i am getting the following error "System.IndexOutOfRangeException: Index was outside the bounds of the array". it is coming from this line of code ;

Line 595: // Build Column Name PartLine 596: strPart1 = strPart1 + "`" + strData[lngIter, 0] + "`,";Line 597:
It may have been caused by the following code;
staticpublicstring buildQuery(string strAction,string strTableName,string[,] strData,string[,] strWhere,string strWhereOverride,string strLimit,string strOffset,string strOrderBy)

{

// Array Definitions

//strData(x,0)=ColumnName

//strData(x,1)=ColumnData

 


You will get this if you use an index that is higher than the number of items in the array. So check if the lngIter is within the index range of the array so you don't pass an index which is higher than the total amount of items in the array.


Hi, i am quite new to programming, so i am unsure if i have declared the arrays properly, however i will show you some code and if you could tell me if you can identify where i have to declare the array.;

The following code is in the page calling up a method;

clsOBJ objDHOC =newclsOBJ();

Pmillio.clsOBJ.buildQuery("INSERT","tblProperty", strData, strWhere,"","1","1","strData");

string[,] strData =newstring[11, 2];

string[,] strWhere =newstring[11, 3];

strData[0, 0] ="StatutoryDate";

strData[0, 1] = txtDate.Text;

The following code is what in the DAL which the one above is referencing;

staticpublicstring buildQuery(string strAction,string strTableName,string[,] strData,string[,] strWhere,string strWhereOverride,string strLimit,string strOffset,string strOrderBy)

{

// Array Definitions

//strData(x,0)=ColumnName

//strData(x,1)=ColumnData

// Ucase

strAction = (strAction);

// Dimension

string strSQL;

int lngIter;

string strPart1 =null;

string strPart2 =null;

0 comments:

Post a Comment