473,796 Members | 2,505 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Error: Index is outside the bounds of the array

I have no idea why this error this is coming and how can i fix it?
Can anyone please help me with it............. .?

public static class BillManager
{
private static Object ExecuteSP(Objec t[] argArray)
{
SqlCommand sqlcmd = new SqlCommand();
SqlConnection sqlconnection1 = new SqlConnection() ;
sqlcmd.Connecti on = sqlconnection1;
Object returnValue;
int paramCount = (int)argArray[1]; // the number of
parameters
sqlcmd.CommandT ext = (string)argArra y[2]; // the whole
query
sqlcmd.CommandT ype = CommandType.Sto redProcedure;

for (int j = 0, i = 3; j < paramCount; i += 4, j++)
{
SqlParameter myPrm = new
SqlParameter((s tring)argArray[i],

(SqlDbType)argA rray[i + 1],

(int)argArray[i + 2]); // Line of Error
myPrm.Value = argArray[i + 3];
sqlcmd.Paramete rs.Add(myPrm);
}

sqlconnection1. Open();

if ((int)argArray[0] == 0)
returnValue = sqlcmd.ExecuteN onQuery(); //
returns the number of rows affected
if ((int)argArray[0] == 1)
returnValue = sqlcmd.ExecuteS calar(); //
returns a single value
else
returnValue =
sqlcmd.ExecuteR eader(CommandBe havior.CloseCon nection); //returns
multiple values

return returnValue;

}
public static void Insert_Utility_ Bill(string CompanyName,
string CustomerId, string Alias, string UserName)
{
object[] prms = new object[11];

prms[0] = 0;
prms[1] = 4;
prms[2] = "INSERT_UTILITY _BILL";
prms[3] = "@COMPANYNA ME";
prms[4] = SqlDbType.VarCh ar;
prms[5] = 50;
prms[6] = CompanyName;
prms[7] = "@CUSTOMERI D";
prms[8] = SqlDbType.NChar ;
prms[9] = 10;
prms[10] = CustomerId.ToCh arArray();
prms[7] = "@ALIAS";
prms[8] = SqlDbType.VarCh ar;
prms[9] = 50;
prms[10] = Alias;
prms[7] = "@USERNAME" ;
prms[8] = SqlDbType.VarCh ar;
prms[9] = 50;
prms[10] = UserName;

ExecuteSP(prms) ;

}
}

Apr 4 '07 #1
4 17624
Well, it's rather obvious. You have an array that you giving an index
to which is outside the bounds of the array.

What happens when you debug this? The debugger will most certainly tell
you what the problem is.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"weird0" <am********@gma il.comwrote in message
news:11******** **************@ l77g2000hsb.goo glegroups.com.. .
I have no idea why this error this is coming and how can i fix it?
Can anyone please help me with it............. .?

public static class BillManager
{
private static Object ExecuteSP(Objec t[] argArray)
{
SqlCommand sqlcmd = new SqlCommand();
SqlConnection sqlconnection1 = new SqlConnection() ;
sqlcmd.Connecti on = sqlconnection1;
Object returnValue;
int paramCount = (int)argArray[1]; // the number of
parameters
sqlcmd.CommandT ext = (string)argArra y[2]; // the whole
query
sqlcmd.CommandT ype = CommandType.Sto redProcedure;

for (int j = 0, i = 3; j < paramCount; i += 4, j++)
{
SqlParameter myPrm = new
SqlParameter((s tring)argArray[i],

(SqlDbType)argA rray[i + 1],

(int)argArray[i + 2]); // Line of Error
myPrm.Value = argArray[i + 3];
sqlcmd.Paramete rs.Add(myPrm);
}

sqlconnection1. Open();

if ((int)argArray[0] == 0)
returnValue = sqlcmd.ExecuteN onQuery(); //
returns the number of rows affected
if ((int)argArray[0] == 1)
returnValue = sqlcmd.ExecuteS calar(); //
returns a single value
else
returnValue =
sqlcmd.ExecuteR eader(CommandBe havior.CloseCon nection); //returns
multiple values

return returnValue;

}
public static void Insert_Utility_ Bill(string CompanyName,
string CustomerId, string Alias, string UserName)
{
object[] prms = new object[11];

prms[0] = 0;
prms[1] = 4;
prms[2] = "INSERT_UTILITY _BILL";
prms[3] = "@COMPANYNA ME";
prms[4] = SqlDbType.VarCh ar;
prms[5] = 50;
prms[6] = CompanyName;
prms[7] = "@CUSTOMERI D";
prms[8] = SqlDbType.NChar ;
prms[9] = 10;
prms[10] = CustomerId.ToCh arArray();
prms[7] = "@ALIAS";
prms[8] = SqlDbType.VarCh ar;
prms[9] = 50;
prms[10] = Alias;
prms[7] = "@USERNAME" ;
prms[8] = SqlDbType.VarCh ar;
prms[9] = 50;
prms[10] = UserName;

ExecuteSP(prms) ;

}
}

Apr 4 '07 #2
Hi,
Ckech the content of the Array object you are sending. This error means that
Your index value grater then the array you are sneding

Regards,
Husam Al-a'araj

"weird0" wrote:
I have no idea why this error this is coming and how can i fix it?
Can anyone please help me with it............. .?

public static class BillManager
{
private static Object ExecuteSP(Objec t[] argArray)
{
SqlCommand sqlcmd = new SqlCommand();
SqlConnection sqlconnection1 = new SqlConnection() ;
sqlcmd.Connecti on = sqlconnection1;
Object returnValue;
int paramCount = (int)argArray[1]; // the number of
parameters
sqlcmd.CommandT ext = (string)argArra y[2]; // the whole
query
sqlcmd.CommandT ype = CommandType.Sto redProcedure;

for (int j = 0, i = 3; j < paramCount; i += 4, j++)
{
SqlParameter myPrm = new
SqlParameter((s tring)argArray[i],

(SqlDbType)argA rray[i + 1],

(int)argArray[i + 2]); // Line of Error
myPrm.Value = argArray[i + 3];
sqlcmd.Paramete rs.Add(myPrm);
}

sqlconnection1. Open();

if ((int)argArray[0] == 0)
returnValue = sqlcmd.ExecuteN onQuery(); //
returns the number of rows affected
if ((int)argArray[0] == 1)
returnValue = sqlcmd.ExecuteS calar(); //
returns a single value
else
returnValue =
sqlcmd.ExecuteR eader(CommandBe havior.CloseCon nection); //returns
multiple values

return returnValue;

}
public static void Insert_Utility_ Bill(string CompanyName,
string CustomerId, string Alias, string UserName)
{
object[] prms = new object[11];

prms[0] = 0;
prms[1] = 4;
prms[2] = "INSERT_UTILITY _BILL";
prms[3] = "@COMPANYNA ME";
prms[4] = SqlDbType.VarCh ar;
prms[5] = 50;
prms[6] = CompanyName;
prms[7] = "@CUSTOMERI D";
prms[8] = SqlDbType.NChar ;
prms[9] = 10;
prms[10] = CustomerId.ToCh arArray();
prms[7] = "@ALIAS";
prms[8] = SqlDbType.VarCh ar;
prms[9] = 50;
prms[10] = Alias;
prms[7] = "@USERNAME" ;
prms[8] = SqlDbType.VarCh ar;
prms[9] = 50;
prms[10] = UserName;

ExecuteSP(prms) ;

}
}

Apr 4 '07 #3
weird0 wrote:
I have no idea why this error this is coming and how can i fix it?
Can anyone please help me with it............. .?
--8<-- snip
>
public static void Insert_Utility_ Bill(string CompanyName,
string CustomerId, string Alias, string UserName)
{
object[] prms = new object[11];

prms[0] = 0;
prms[1] = 4;
prms[2] = "INSERT_UTILITY _BILL";
prms[3] = "@COMPANYNA ME";
prms[4] = SqlDbType.VarCh ar;
prms[5] = 50;
prms[6] = CompanyName;
prms[7] = "@CUSTOMERI D";
prms[8] = SqlDbType.NChar ;
prms[9] = 10;
prms[10] = CustomerId.ToCh arArray();
Hm... What number might be following 10? ;)
prms[7] = "@ALIAS";
prms[8] = SqlDbType.VarCh ar;
prms[9] = 50;
prms[10] = Alias;
prms[7] = "@USERNAME" ;
prms[8] = SqlDbType.VarCh ar;
prms[9] = 50;
prms[10] = UserName;

ExecuteSP(prms) ;

}
}
--
Göran Andersson
_____
http://www.guffa.com
Apr 4 '07 #4
On 4 Apr 2007 12:45:07 -0700, "weird0" <am********@gma il.comwrote:
I have no idea why this error this is coming and how can i fix it?
Can anyone please help me with it............. .?
[snip]
>(int)argArra y[i + 2]); // Line of Error
Step through your program with the Debugger. Set a watch on the
values of i and on argArray. Check the value of i+2 against the size
of argArray every time through your loop.

rossum

Apr 4 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2766
by: Eugene | last post by:
Hello all, I've been trying to figure this out for a few days now, and still have no clue what's going on... I have a few related tables in MS Access (Clients, Cars, Sales), and a datagrid, binded to dataview. Here's a catch - whenever I select a client, and then find a car which belongs to this client, and click on empty space in datagrid (that is in gray area below rows) - I get "Index was outside the bounds of the array" error......
4
2699
by: Andrea | last post by:
Hi there, I have a problem. I am running a program that used to work when suddenly...it stop working. I got this message: "Index was outside the bounds of the array" Is there anyone who knows how I can solve this problem?
1
2339
by: Joe | last post by:
This is a weird problem. when doing trying to add a tabpage to a tabcontrol I get an error: Index was outside the bounds of the array. Now this only happens when I call a function from within a callback for an Async webmethod call. My guess is that it has something to do with the threads not being in sync yet.
1
1254
by: Jéjé | last post by:
Hi, I receive this error when I execute a beta 2 ASP.Net application on an RTM server: Index was outside the bounds of the array. System.Data.SqlClient.SqlDataReader.ReadColumn(Int32 i, Boolean setTimeout) +342 System.Data.SqlClient.SqlDataReader.GetDateTime(Int32 i) +21
0
1300
by: Trapulo | last post by:
I've a datagrid filled with a collection of objects that inherits from basecollection. When I remove an item from this collection and then click onto the datagrid, I've always this error: "Index was outside the bounds of the array datagrid" I've tried this structure: Dim oldList As Business.MyBaseCollection = DirectCast(dgDetails.DataSource,
3
2545
by: Tim | last post by:
Hi, The following code works just fine in VS 2003 but in VS 2005 I am getting an error: The code: DateTime dClose = System.Convert.ToDateTime(now.Date.ToString("MMM dd, yyyy") + " " + storeClose.Hour + ":" + storeClose.Minute); The error:
11
2810
by: Tim | last post by:
Hi, I am trying to do something simple. Convert a string date to datetime but it is not working and is giving me a baffling error! System.Convert.ToDateTime("Jan 30, 2006") 'System.Convert.ToDateTime("Jan 30, 2006")' threw an exception of type 'System.IndexOutOfRangeException' base {System.SystemException}: {"Index was outside the bounds of the array."}
0
2382
by: Beaker | last post by:
I am having some trouble with an array object and a web service I have. I have a farly simple user object public class User { private Guid myUserId; public Guid UserId { get { return myUserId; }
3
2092
by: kalaivani572 | last post by:
i am getting "Index was outside the bounds of the array." error when i try to get the checked items from list view. the code is private void btnFinish_Click(object sender, EventArgs e) { WaitCallback async = new WaitCallback(Executefeed); ThreadPool.QueueUserWorkItem(async, alParams); waitBar.ShowDialog(); }
0
9528
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10456
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10230
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10174
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10012
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6788
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5575
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3731
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2926
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.